summaryrefslogtreecommitdiffstats
path: root/scintilla/src/Editor.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'scintilla/src/Editor.cxx')
-rw-r--r--scintilla/src/Editor.cxx163
1 files changed, 118 insertions, 45 deletions
diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx
index 99119a6..147e888 100644
--- a/scintilla/src/Editor.cxx
+++ b/scintilla/src/Editor.cxx
@@ -630,6 +630,7 @@ void Editor::SetSelection(SelectionPosition currentPos_, SelectionPosition ancho
sel.RangeMain() = rangeNew;
SetRectangularRange();
ClaimSelection();
+ SetHoverIndicatorPosition(sel.MainCaret());
if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) {
RedrawSelMargin();
@@ -657,6 +658,7 @@ void Editor::SetSelection(SelectionPosition currentPos_) {
SelectionRange(SelectionPosition(currentPos_), sel.RangeMain().anchor);
}
ClaimSelection();
+ SetHoverIndicatorPosition(sel.MainCaret());
if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) {
RedrawSelMargin();
@@ -678,6 +680,7 @@ void Editor::SetEmptySelection(SelectionPosition currentPos_) {
sel.RangeMain() = rangeNew;
SetRectangularRange();
ClaimSelection();
+ SetHoverIndicatorPosition(sel.MainCaret());
if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) {
RedrawSelMargin();
@@ -1869,28 +1872,9 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
// Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
// characters representing themselves.
} else {
- // Unroll 1 to 3 byte UTF-8 sequences. See reference data at:
- // http://www.cl.cam.ac.uk/~mgk25/unicode.html
- // http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
- if (byte < 0xE0) {
- int byte2 = static_cast<unsigned char>(s[1]);
- if ((byte2 & 0xC0) == 0x80) {
- // Two-byte-character lead-byte followed by a trail-byte.
- byte = (((byte & 0x1F) << 6) | (byte2 & 0x3F));
- }
- // A two-byte-character lead-byte not followed by trail-byte
- // represents itself.
- } else if (byte < 0xF0) {
- int byte2 = static_cast<unsigned char>(s[1]);
- int byte3 = static_cast<unsigned char>(s[2]);
- if (((byte2 & 0xC0) == 0x80) && ((byte3 & 0xC0) == 0x80)) {
- // Three-byte-character lead byte followed by two trail bytes.
- byte = (((byte & 0x0F) << 12) | ((byte2 & 0x3F) << 6) |
- (byte3 & 0x3F));
- }
- // A three-byte-character lead-byte not followed by two trail-bytes
- // represents itself.
- }
+ unsigned int utf32[1] = { 0 };
+ UTF32FromUTF8(s, len, utf32, ELEMENTS(utf32));
+ byte = utf32[0];
}
NotifyChar(byte);
}
@@ -1988,6 +1972,7 @@ void Editor::ClearSelection(bool retainMultipleSelections) {
ThinRectangularRange();
sel.RemoveDuplicates();
ClaimSelection();
+ SetHoverIndicatorPosition(sel.MainCaret());
}
void Editor::ClearAll() {
@@ -3669,7 +3654,10 @@ long Editor::FindText(
if (!pdoc->HasCaseFolder())
pdoc->SetCaseFolder(CaseFolderForEncoding());
try {
- int pos = pdoc->FindText(ft->chrg.cpMin, ft->chrg.cpMax, ft->lpstrText,
+ long pos = pdoc->FindText(
+ static_cast<int>(ft->chrg.cpMin),
+ static_cast<int>(ft->chrg.cpMax),
+ ft->lpstrText,
(wParam & SCFIND_MATCHCASE) != 0,
(wParam & SCFIND_WHOLEWORD) != 0,
(wParam & SCFIND_WORDSTART) != 0,
@@ -3680,7 +3668,7 @@ long Editor::FindText(
ft->chrgText.cpMin = pos;
ft->chrgText.cpMax = pos + lengthFound;
}
- return pos;
+ return static_cast<int>(pos);
} catch (RegexError &) {
errorStatus = SC_STATUS_WARN_REGEX;
return -1;
@@ -3714,7 +3702,7 @@ long Editor::SearchText(
sptr_t lParam) { ///< The text to search for.
const char *txt = reinterpret_cast<char *>(lParam);
- int pos;
+ long pos;
int lengthFound = istrlen(txt);
if (!pdoc->HasCaseFolder())
pdoc->SetCaseFolder(CaseFolderForEncoding());
@@ -3741,7 +3729,7 @@ long Editor::SearchText(
return -1;
}
if (pos != -1) {
- SetSelection(pos, pos + lengthFound);
+ SetSelection(static_cast<int>(pos), static_cast<int>(pos + lengthFound));
}
return pos;
@@ -3774,7 +3762,7 @@ long Editor::SearchInTarget(const char *text, int length) {
if (!pdoc->HasCaseFolder())
pdoc->SetCaseFolder(CaseFolderForEncoding());
try {
- int pos = pdoc->FindText(targetStart, targetEnd, text,
+ long pos = pdoc->FindText(targetStart, targetEnd, text,
(searchFlags & SCFIND_MATCHCASE) != 0,
(searchFlags & SCFIND_WHOLEWORD) != 0,
(searchFlags & SCFIND_WORDSTART) != 0,
@@ -3782,8 +3770,8 @@ long Editor::SearchInTarget(const char *text, int length) {
searchFlags,
&lengthFound);
if (pos != -1) {
- targetStart = pos;
- targetEnd = pos + lengthFound;
+ targetStart = static_cast<int>(pos);
+ targetEnd = static_cast<int>(pos + lengthFound);
}
return pos;
} catch (RegexError &) {
@@ -4133,6 +4121,7 @@ static bool AllowVirtualSpace(int virtualSpaceOptions, bool rectangular) {
}
void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifiers) {
+ SetHoverIndicatorPoint(pt);
//Platform::DebugPrintf("ButtonDown %d %d = %d alt=%d %d\n", curTime, lastClickTime, curTime - lastClickTime, alt, inDragDrop);
ptMouseLast = pt;
const bool ctrl = (modifiers & SCI_CTRL) != 0;
@@ -4331,6 +4320,36 @@ bool Editor::PointIsHotspot(Point pt) {
return PositionIsHotspot(pos);
}
+void Editor::SetHoverIndicatorPosition(int position) {
+ int hoverIndicatorPosPrev = hoverIndicatorPos;
+ hoverIndicatorPos = INVALID_POSITION;
+ if (vs.indicatorsDynamic == 0)
+ return;
+ if (position != INVALID_POSITION) {
+ for (Decoration *deco = pdoc->decorations.root; deco; deco = deco->next) {
+ if (vs.indicators[deco->indicator].IsDynamic()) {
+ if (pdoc->decorations.ValueAt(deco->indicator, position)) {
+ hoverIndicatorPos = position;
+ }
+ }
+ }
+ }
+ if (hoverIndicatorPosPrev != hoverIndicatorPos) {
+ if (hoverIndicatorPosPrev != INVALID_POSITION)
+ InvalidateRange(hoverIndicatorPosPrev, hoverIndicatorPosPrev + 1);
+ if (hoverIndicatorPos != INVALID_POSITION)
+ InvalidateRange(hoverIndicatorPos, hoverIndicatorPos + 1);
+ }
+}
+
+void Editor::SetHoverIndicatorPoint(Point pt) {
+ if (vs.indicatorsDynamic == 0) {
+ SetHoverIndicatorPosition(INVALID_POSITION);
+ } else {
+ SetHoverIndicatorPosition(PositionFromLocation(pt, true, true));
+ }
+}
+
void Editor::SetHotSpotRange(Point *pt) {
if (pt) {
int pos = PositionFromLocation(*pt, false, true);
@@ -4473,12 +4492,18 @@ void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) {
// Display regular (drag) cursor over selection
if (PointInSelection(pt) && !SelectionEmpty()) {
DisplayCursor(Window::cursorArrow);
- } else if (PointIsHotspot(pt)) {
- DisplayCursor(Window::cursorHand);
- SetHotSpotRange(&pt);
} else {
- DisplayCursor(Window::cursorText);
- SetHotSpotRange(NULL);
+ SetHoverIndicatorPoint(pt);
+ if (PointIsHotspot(pt)) {
+ DisplayCursor(Window::cursorHand);
+ SetHotSpotRange(&pt);
+ } else {
+ if (hoverIndicatorPos != invalidPosition)
+ DisplayCursor(Window::cursorHand);
+ else
+ DisplayCursor(Window::cursorText);
+ SetHotSpotRange(NULL);
+ }
}
}
}
@@ -4491,6 +4516,8 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) {
//Platform::DebugPrintf("ButtonUp %d %d\n", HaveMouseCapture(), inDragDrop);
SelectionPosition newPos = SPositionFromLocation(pt, false, false,
AllowVirtualSpace(virtualSpaceOptions, sel.IsRectangular()));
+ if (hoverIndicatorPos != INVALID_POSITION)
+ InvalidateRange(newPos.Position(), newPos.Position() + 1);
newPos = MovePositionOutsideChar(newPos, sel.MainCaret() - newPos.Position());
if (inDragDrop == ddInitial) {
inDragDrop = ddNone;
@@ -4806,6 +4833,7 @@ void Editor::SetBraceHighlight(Position pos0, Position pos1, int matchStyle) {
void Editor::SetAnnotationHeights(int start, int end) {
if (vs.annotationVisible) {
+ RefreshStyleData();
bool changedHeight = false;
for (int line=start; line<end && line<pdoc->LinesTotal(); line++) {
int linesWrapped = 1;
@@ -4856,6 +4884,9 @@ void Editor::SetDocPointer(Document *document) {
view.llc.Deallocate();
NeedWrapping();
+ hotspot = Range(invalidPosition);
+ hoverIndicatorPos = invalidPosition;
+
view.ClearAllTabstops();
pdoc->AddWatcher(this, 0);
@@ -5309,7 +5340,7 @@ sptr_t Editor::StringResult(sptr_t lParam, const char *val) {
sptr_t Editor::BytesResult(sptr_t lParam, const unsigned char *val, size_t len) {
// No NUL termination: len is number of valid/displayed bytes
- if (lParam) {
+ if ((lParam) && (len > 0)) {
char *ptr = CharPtrFromSPtr(lParam);
if (val)
memcpy(ptr, val, len);
@@ -5527,6 +5558,11 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_GETTARGETEND:
return targetEnd;
+ case SCI_SETTARGETRANGE:
+ targetStart = static_cast<int>(wParam);
+ targetEnd = static_cast<int>(lParam);
+ break;
+
case SCI_TARGETFROMSELECTION:
if (sel.MainCaret() < sel.MainAnchor()) {
targetStart = sel.MainCaret();
@@ -5537,6 +5573,11 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
}
break;
+ case SCI_GETTARGETTEXT: {
+ std::string text = RangeText(targetStart, targetEnd);
+ return BytesResult(lParam, reinterpret_cast<const unsigned char *>(text.c_str()), text.length());
+ }
+
case SCI_REPLACETARGET:
PLATFORM_ASSERT(lParam);
return ReplaceTarget(false, CharPtrFromSPtr(lParam), static_cast<int>(wParam));
@@ -5625,12 +5666,12 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
if (lParam == 0)
return 0;
Sci_TextRange *tr = reinterpret_cast<Sci_TextRange *>(lParam);
- int cpMax = tr->chrg.cpMax;
+ int cpMax = static_cast<int>(tr->chrg.cpMax);
if (cpMax == -1)
cpMax = pdoc->Length();
PLATFORM_ASSERT(cpMax <= pdoc->Length());
- int len = cpMax - tr->chrg.cpMin; // No -1 as cpMin and cpMax are referring to inter character positions
- pdoc->GetCharRange(tr->lpstrText, tr->chrg.cpMin, len);
+ int len = static_cast<int>(cpMax - tr->chrg.cpMin); // No -1 as cpMin and cpMax are referring to inter character positions
+ pdoc->GetCharRange(tr->lpstrText, static_cast<int>(tr->chrg.cpMin), len);
// Spec says copied text is terminated with a NUL
tr->lpstrText[len] = '\0';
return len; // Not including NUL
@@ -5868,9 +5909,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return 0;
Sci_TextRange *tr = reinterpret_cast<Sci_TextRange *>(lParam);
int iPlace = 0;
- for (int iChar = tr->chrg.cpMin; iChar < tr->chrg.cpMax; iChar++) {
- tr->lpstrText[iPlace++] = pdoc->CharAt(iChar);
- tr->lpstrText[iPlace++] = pdoc->StyleAt(iChar);
+ for (long iChar = tr->chrg.cpMin; iChar < tr->chrg.cpMax; iChar++) {
+ tr->lpstrText[iPlace++] = pdoc->CharAt(static_cast<int>(iChar));
+ tr->lpstrText[iPlace++] = pdoc->StyleAt(static_cast<int>(iChar));
}
tr->lpstrText[iPlace] = '\0';
tr->lpstrText[iPlace + 1] = '\0';
@@ -6781,23 +6822,55 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_INDICSETSTYLE:
if (wParam <= INDIC_MAX) {
- vs.indicators[wParam].style = static_cast<int>(lParam);
+ vs.indicators[wParam].sacNormal.style = static_cast<int>(lParam);
+ vs.indicators[wParam].sacHover.style = static_cast<int>(lParam);
InvalidateStyleRedraw();
}
break;
case SCI_INDICGETSTYLE:
- return (wParam <= INDIC_MAX) ? vs.indicators[wParam].style : 0;
+ return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacNormal.style : 0;
case SCI_INDICSETFORE:
if (wParam <= INDIC_MAX) {
- vs.indicators[wParam].fore = ColourDesired(static_cast<long>(lParam));
+ vs.indicators[wParam].sacNormal.fore = ColourDesired(static_cast<long>(lParam));
+ vs.indicators[wParam].sacHover.fore = ColourDesired(static_cast<long>(lParam));
InvalidateStyleRedraw();
}
break;
case SCI_INDICGETFORE:
- return (wParam <= INDIC_MAX) ? vs.indicators[wParam].fore.AsLong() : 0;
+ return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacNormal.fore.AsLong() : 0;
+
+ case SCI_INDICSETHOVERSTYLE:
+ if (wParam <= INDIC_MAX) {
+ vs.indicators[wParam].sacHover.style = static_cast<int>(lParam);
+ InvalidateStyleRedraw();
+ }
+ break;
+
+ case SCI_INDICGETHOVERSTYLE:
+ return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacHover.style : 0;
+
+ case SCI_INDICSETHOVERFORE:
+ if (wParam <= INDIC_MAX) {
+ vs.indicators[wParam].sacHover.fore = ColourDesired(static_cast<long>(lParam));
+ InvalidateStyleRedraw();
+ }
+ break;
+
+ case SCI_INDICGETHOVERFORE:
+ return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacHover.fore.AsLong() : 0;
+
+ case SCI_INDICSETFLAGS:
+ if (wParam <= INDIC_MAX) {
+ vs.indicators[wParam].SetFlags(static_cast<int>(lParam));
+ InvalidateStyleRedraw();
+ }
+ break;
+
+ case SCI_INDICGETFLAGS:
+ return (wParam <= INDIC_MAX) ? vs.indicators[wParam].Flags() : 0;
case SCI_INDICSETUNDER:
if (wParam <= INDIC_MAX) {