diff options
author | nyamatongwe <unknown> | 2001-12-19 07:31:46 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2001-12-19 07:31:46 +0000 |
commit | b1e7aaa793be9971d24d426c60923a072211c356 (patch) | |
tree | 5221f52d09adbd6f8626f98af2c26fcbf0da8754 /src | |
parent | 4111db4baf3e8dcd726be593f7a0ed00768b6f26 (diff) | |
download | scintilla-mirror-b1e7aaa793be9971d24d426c60923a072211c356.tar.gz |
Fixed, regularised and simplified movement of brace highlights and
selection when insertions and deletions are performed.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 478c20fb2..68d283bc4 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2040,6 +2040,29 @@ void Editor::NotifySavePoint(Document*, void *, bool atSavePoint) { NotifySavePoint(atSavePoint); } +// Move a position so it is still after the same character as before the insertion. +static inline int MovePositionForInsertion(int position, int startInsertion, int length) { + if (position > startInsertion) { + return position + length; + } + return position; +} + +// Move a position so it is still after the same character as before the deletion if that +// character is still present else after the previous surviving character. +static inline int MovePositionForDeletion(int position, int startDeletion, int length) { + if (position > startDeletion) { + int endDeletion = startDeletion + length; + if (position > endDeletion) { + return position - length; + } else { + return startDeletion; + } + } else { + return position; + } +} + void Editor::NotifyModified(Document*, DocModification mh, void *) { needUpdateUI = true; if (paintState == painting) { @@ -2055,48 +2078,15 @@ void Editor::NotifyModified(Document*, DocModification mh, void *) { } else { // Move selection and brace highlights if (mh.modificationType & SC_MOD_INSERTTEXT) { - if (currentPos > mh.position) { - currentPos += mh.length; - } - if (anchor > mh.position) { - anchor += mh.length; - } - if (braces[0] > mh.position) { - braces[0] += mh.length; - } - if (braces[1] > mh.position) { - braces[1] += mh.length; - } + currentPos = MovePositionForInsertion(currentPos, mh.position, mh.length); + anchor = MovePositionForInsertion(anchor, mh.position, mh.length); + braces[0] = MovePositionForInsertion(braces[0], mh.position, mh.length); + braces[1] = MovePositionForInsertion(braces[1], mh.position, mh.length); } else if (mh.modificationType & SC_MOD_DELETETEXT) { - int endPos = mh.position + mh.length; - if (currentPos > mh.position) { - if (currentPos > endPos) { - currentPos -= mh.length; - } else { - currentPos = endPos; - } - } - if (anchor > mh.position) { - if (anchor > endPos) { - anchor -= mh.length; - } else { - anchor = endPos; - } - } - if (braces[0] > mh.position) { - if (braces[0] > endPos) { - braces[0] -= mh.length; - } else { - braces[0] = endPos; - } - } - if (braces[1] > mh.position) { - if (braces[1] > endPos) { - braces[1] -= mh.length; - } else { - braces[1] = endPos; - } - } + currentPos = MovePositionForDeletion(currentPos, mh.position, mh.length); + anchor = MovePositionForDeletion(anchor, mh.position, mh.length); + braces[0] = MovePositionForDeletion(braces[0], mh.position, mh.length); + braces[1] = MovePositionForDeletion(braces[1], mh.position, mh.length); } if (cs.LinesDisplayed() < cs.LinesInDoc()) { // Some lines are hidden so may need shown. |