aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2012-05-08 22:07:57 +1000
committernyamatongwe <devnull@localhost>2012-05-08 22:07:57 +1000
commite3ecdee5158583f43b6bb2cf2b461c81cb9608e3 (patch)
treec0874fe0acc1e3bea28a310cbbc5b4339fd3ca46 /src
parent5a5b23882ea5f084f591dbe4337eb5b67c23cdb9 (diff)
downloadscintilla-mirror-e3ecdee5158583f43b6bb2cf2b461c81cb9608e3.tar.gz
Feature #3520037. Trim current selection when setting a word or
line selection to avoid any doubly selected ranges.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx15
-rw-r--r--src/Editor.h1
2 files changed, 11 insertions, 5 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 3d5257059..1a591b325 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -6152,6 +6152,11 @@ Window::Cursor Editor::GetMarginCursor(Point pt) {
return Window::cursorReverseArrow;
}
+void Editor::TrimAndSetSelection(int currentPos_, int anchor_) {
+ sel.TrimSelection(SelectionRange(currentPos_, anchor_));
+ SetSelection(currentPos_, anchor_);
+}
+
void Editor::LineSelection(int lineCurrentPos_, int lineAnchorPos_, bool wholeLine) {
int selCurrentPos, selAnchorPos;
if (wholeLine) {
@@ -6182,7 +6187,7 @@ void Editor::LineSelection(int lineCurrentPos_, int lineAnchorPos_, bool wholeLi
selAnchorPos = StartEndDisplayLine(lineAnchorPos_, true);
}
}
- SetSelection(selCurrentPos, selAnchorPos);
+ TrimAndSetSelection(selCurrentPos, selAnchorPos);
}
void Editor::WordSelection(int pos) {
@@ -6192,20 +6197,20 @@ void Editor::WordSelection(int pos) {
// This ensures that a series of empty lines isn't counted as a single "word".
if (!pdoc->IsLineEndPosition(pos))
pos = pdoc->ExtendWordSelect(pdoc->MovePositionOutsideChar(pos + 1, 1), -1);
- SetSelection(pos, wordSelectAnchorEndPos);
+ TrimAndSetSelection(pos, wordSelectAnchorEndPos);
} else if (pos > wordSelectAnchorEndPos) {
// Extend forward to the word containing the character to the left of pos.
// Skip ExtendWordSelect if the line is empty or if pos is the first position on the line.
// This ensures that a series of empty lines isn't counted as a single "word".
if (pos > pdoc->LineStart(pdoc->LineFromPosition(pos)))
pos = pdoc->ExtendWordSelect(pdoc->MovePositionOutsideChar(pos - 1, -1), 1);
- SetSelection(pos, wordSelectAnchorStartPos);
+ TrimAndSetSelection(pos, wordSelectAnchorStartPos);
} else {
// Select only the anchored word
if (pos >= originalAnchorPos)
- SetSelection(wordSelectAnchorEndPos, wordSelectAnchorStartPos);
+ TrimAndSetSelection(wordSelectAnchorEndPos, wordSelectAnchorStartPos);
else
- SetSelection(wordSelectAnchorStartPos, wordSelectAnchorEndPos);
+ TrimAndSetSelection(wordSelectAnchorStartPos, wordSelectAnchorEndPos);
}
}
diff --git a/src/Editor.h b/src/Editor.h
index c33f5b5f1..f8ab19d9e 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -493,6 +493,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
bool PointInSelection(Point pt);
bool PointInSelMargin(Point pt);
Window::Cursor GetMarginCursor(Point pt);
+ void TrimAndSetSelection(int currentPos_, int anchor_);
void LineSelection(int lineCurrentPos_, int lineAnchorPos_, bool wholeLine);
void WordSelection(int pos);
void DwellEnd(bool mouseMoved);