diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Selection.cxx | 21 | ||||
-rw-r--r-- | src/Selection.h | 2 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/Selection.cxx b/src/Selection.cxx index 9b08ea001..5667bf234 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -23,12 +23,16 @@ using namespace Scintilla; -void SelectionPosition::MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) noexcept { +void SelectionPosition::MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length, bool moveForEqual) noexcept { if (insertion) { if (position == startChange) { + // Always consume virtual space const Sci::Position virtualLengthRemove = std::min(length, virtualSpace); virtualSpace -= virtualLengthRemove; - position += virtualLengthRemove; + if (moveForEqual) { + const Sci::Position lengthAfterVirtualRemove = length - virtualLengthRemove; + position += lengthAfterVirtualRemove; + } } else if (position > startChange) { position += length; } @@ -85,8 +89,17 @@ Sci::Position SelectionRange::Length() const noexcept { } void SelectionRange::MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) noexcept { - caret.MoveForInsertDelete(insertion, startChange, length); - anchor.MoveForInsertDelete(insertion, startChange, length); + // For insertions that occur at the start of the selection move both the start + // and end of the selection to preserve the selected length. + // The end will automatically move since it is after the insertion, so determine + // 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; + + caret.MoveForInsertDelete(insertion, startChange, length, caretStart); + anchor.MoveForInsertDelete(insertion, startChange, length, anchorStart); } bool SelectionRange::Contains(Sci::Position pos) const noexcept { diff --git a/src/Selection.h b/src/Selection.h index 11a6f097a..741b75277 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -23,7 +23,7 @@ public: position = 0; virtualSpace = 0; } - void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) noexcept; + void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length, bool moveForEqual) noexcept; bool operator ==(const SelectionPosition &other) const noexcept { return position == other.position && virtualSpace == other.virtualSpace; } |