aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
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
commitcf034c5958bd83d4a0f71ff79a47e4f76534d5d6 (patch)
tree709910a1d33720c95fa732e5cd7772e4befed213 /src
parentdf312dd97f04aaed14f528f2f822302042d756c5 (diff)
downloadscintilla-mirror-cf034c5958bd83d4a0f71ff79a47e4f76534d5d6.tar.gz
Bug [#2140]. Move rather than grow selection when insertion at start.
Diffstat (limited to 'src')
-rw-r--r--src/Selection.cxx21
-rw-r--r--src/Selection.h2
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;
}