aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Selection.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2019-11-24 08:04:57 +1100
committerNeil <nyamatongwe@gmail.com>2019-11-24 08:04:57 +1100
commit63d10d1054d9987f647bf654be54f355d1dc40d6 (patch)
treea414517dac7a44303b9007c3e18910dcb661364e /src/Selection.cxx
parent0fac577852fdc97275d371032247c5428afd7876 (diff)
downloadscintilla-mirror-63d10d1054d9987f647bf654be54f355d1dc40d6.tar.gz
Backport: Bug [#2140]. Move rather than grow selection when insertion at start.
Backport of changeset 7773:20f353cd5507.
Diffstat (limited to 'src/Selection.cxx')
-rw-r--r--src/Selection.cxx21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/Selection.cxx b/src/Selection.cxx
index 6893ee04e..bd48a2f9f 100644
--- a/src/Selection.cxx
+++ b/src/Selection.cxx
@@ -22,12 +22,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;
}
@@ -84,8 +88,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 {