diff options
author | Neil <nyamatongwe@gmail.com> | 2019-11-26 09:09:26 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2019-11-26 09:09:26 +1100 |
commit | ab36224e033e1772c604cad2ab8c5f831f24357f (patch) | |
tree | 252744732d806ed96bd3f1e98a54237bc958dc90 | |
parent | 22eee409c31068626864be47848673c73d31f413 (diff) | |
download | scintilla-mirror-ab36224e033e1772c604cad2ab8c5f831f24357f.tar.gz |
Backport: Bug [#2140]. Fix where anchor and caret differ only in amount of virtual space
so one was considered start and was moved for an insertion at that position.
This could flip the order of the positions or change the length of the selection.
Backport of changeset 7775:a9a0edc8f2f2.
-rw-r--r-- | src/Selection.cxx | 4 | ||||
-rw-r--r-- | test/simpleTests.py | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/Selection.cxx b/src/Selection.cxx index 47aba5c31..fbdd375c6 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -95,8 +95,8 @@ void SelectionRange::MoveForInsertDelete(bool insertion, Sci::Position startChan // which position is the start and pass this into // SelectionPosition::MoveForInsertDelete. // There isn't any reason to move an empty selection so don't move it. - const bool caretStart = caret < anchor; - const bool anchorStart = anchor < caret; + const bool caretStart = caret.Position() < anchor.Position(); + const bool anchorStart = anchor.Position() < caret.Position(); caret.MoveForInsertDelete(insertion, startChange, length, caretStart); anchor.MoveForInsertDelete(insertion, startChange, length, anchorStart); diff --git a/test/simpleTests.py b/test/simpleTests.py index f56066690..1ede72da3 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -1665,6 +1665,24 @@ class TestMultiSelection(unittest.TestCase): self.assertEquals(self.ed.Contents(), b'a1') self.assertEquals(self.textOfSelection(0), b'') + def testInsertThroughVirtualSpace(self): + self.ed.SetContents(b"a") + self.ed.SetSelection(1, 1) + self.ed.SetSelectionNAnchorVirtualSpace(0, 2) + self.ed.SetSelectionNCaretVirtualSpace(0, 3) + self.assertEquals(self.selectionRepresentation(0), "1+2v-1+3v") + self.assertEquals(self.textOfSelection(0), b'') + + # Append '1' past current virtual space + self.ed.SetTargetRange(1, 1) + self.ed.SetTargetStartVirtualSpace(4) + self.ed.SetTargetEndVirtualSpace(5) + self.ed.ReplaceTarget(1, b'1') + # Virtual space of selection all converted to real positions + self.assertEquals(self.selectionRepresentation(0), "3-4") + self.assertEquals(self.ed.Contents(), b'a 1') + self.assertEquals(self.textOfSelection(0), b' ') + class TestModalSelection(unittest.TestCase): |