diff options
-rw-r--r-- | include/Scintilla.h | 1 | ||||
-rw-r--r-- | include/Scintilla.iface | 3 | ||||
-rw-r--r-- | src/Editor.cxx | 24 |
3 files changed, 19 insertions, 9 deletions
diff --git a/include/Scintilla.h b/include/Scintilla.h index 65a95b8e9..664d11879 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -411,6 +411,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define CARET_CENTER 0x02 #define CARET_STRICT 0x04 #define CARET_XEVEN 0x08 +#define CARET_XJUMPS 0x10 #define SCI_SETCARETPOLICY 2369 #define SCI_LINESONSCREEN 2370 #define SCI_USEPOPUP 2371 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index bb40634f3..a8b42dbdb 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1079,6 +1079,9 @@ val CARET_STRICT=0x04 # If CARET_XEVEN set then both left and right margins are given equal weight # rather than favouring left following behaviour. val CARET_XEVEN=0x08 +# If CARET_XJUMPS set then when caret reaches the margin the display jumps +# enough to leave the caret solidly within the display. +val CARET_XJUMPS=0x10 # Set the way the line the caret is on is kept visible. fun void SetCaretPolicy=2369(int caretPolicy, int caretSlop) diff --git a/src/Editor.cxx b/src/Editor.cxx index 1416fad8f..b4e192558 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -588,15 +588,22 @@ void Editor::EnsureCaretVisible(bool useMargin, bool vert, bool horiz) { int lineCaret = cs.DisplayFromDoc(pdoc->LineFromPosition(posCaret)); ptBottomCaret.y += vs.lineHeight - 1; - // Ensure the caret is reasonably visible in context. + // Ensure the caret is reasonably visible in context: + // xMargin must equal to xCaretMargin, with a minimum of 2 and a maximum of + // slightly less than half the width of the text area. int xMargin = Platform::Clamp(xCaretMargin, 2, Platform::Maximum(rcClient.Width() - 10, 4) / 2); if (!useMargin) xMargin = 2; - // Ensure certain amount of text visible on both sides of caret - // So move if caret just on edge - rcClient.left = rcClient.left + xMargin; - rcClient.right = rcClient.right - xMargin; + // If we scroll the display, we use a minimum amount of xMargin. + int offsetLeft = rcClient.left + xMargin; + int offsetRight = rcClient.right - xMargin; + // If we are in XJUMPS mode, then when the margin is reached, the + // offset jumps so that it won't need to move agin for a while. + if (!(caretPolicy & CARET_XJUMPS)) { + rcClient.left = offsetLeft; + rcClient.right = offsetRight; + } // Vertical positioning if (vert && (!rcClient.Contains(pt) || !rcClient.Contains(ptBottomCaret) || (caretPolicy & CARET_STRICT))) { @@ -627,10 +634,10 @@ void Editor::EnsureCaretVisible(bool useMargin, bool vert, bool horiz) { if (horiz) { int xOffsetNew = xOffset; if (pt.x < rcClient.left) { - xOffsetNew = xOffset - (rcClient.left - pt.x); + xOffsetNew = xOffset - (offsetLeft - pt.x); } else if (((caretPolicy & CARET_XEVEN) && ((xOffset > 0) && useMargin)) || pt.x >= rcClient.right) { - xOffsetNew = xOffset + (pt.x - rcClient.right); - int xOffsetEOL = xOffset + (ptEOL.x - rcClient.right) - xMargin + 2; + xOffsetNew = xOffset + (pt.x - offsetRight); + int xOffsetEOL = xOffset + (ptEOL.x - offsetRight) - xMargin + 2; //Platform::DebugPrintf("Margin %d %d\n", xOffsetNew, xOffsetEOL); // Ensure don't scroll out into empty space if (xOffsetNew > xOffsetEOL) @@ -2035,7 +2042,6 @@ void Editor::NotifyModified(Document*, DocModification mh, void *) { } } if (mh.linesAdded != 0) { - // Update contraction state for inserted and removed lines // lineOfPos should be calculated in context of state before modification, shouldn't it int lineOfPos = pdoc->LineFromPosition(mh.position); |