aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2015-06-16 13:11:03 +1000
committerNeil <nyamatongwe@gmail.com>2015-06-16 13:11:03 +1000
commitdfa87cc18cc453a12113a53671c75c8461f437d8 (patch)
treea1469092ecb9c9066eb00e29604115e3db76ef1d
parentf1bd8d5f4ac8a741df0b10000f09345752f6e6af (diff)
downloadscintilla-mirror-dfa87cc18cc453a12113a53671c75c8461f437d8.tar.gz
Clean up some selection operations. Commonly when changing selection modes,
all of the selection needs to be redrawn so that is implmeneted in Editor::InvalidateWholeSelection. Any extra selections should be discarded with only the main remaining so that is Selection::DropAdditionalRanges. Some default parameters led to less clarity so they no longer have default values. Both Editor::MovePositionTo methods always returned 0 which was ignored so they are now void. Some variables were made const.
-rw-r--r--src/Editor.cxx52
-rw-r--r--src/Editor.h9
-rw-r--r--src/Selection.cxx4
-rw-r--r--src/Selection.h1
4 files changed, 36 insertions, 30 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 678f2e927..a1099790c 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -608,6 +608,10 @@ void Editor::InvalidateSelection(SelectionRange newMain, bool invalidateWholeSel
InvalidateRange(firstAffected, lastAffected);
}
+void Editor::InvalidateWholeSelection() {
+ InvalidateSelection(sel.RangeMain(), true);
+}
+
void Editor::SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_) {
currentPos_ = ClampPositionIntoDocument(currentPos_);
anchor_ = ClampPositionIntoDocument(anchor_);
@@ -799,9 +803,9 @@ SelectionPosition Editor::MovePositionOutsideChar(SelectionPosition pos, int mov
return pos;
}
-int Editor::MovePositionTo(SelectionPosition newPos, Selection::selTypes selt, bool ensureVisible) {
- bool simpleCaret = (sel.Count() == 1) && sel.Empty();
- SelectionPosition spCaret = sel.Last();
+void Editor::MovePositionTo(SelectionPosition newPos, Selection::selTypes selt, bool ensureVisible) {
+ const bool simpleCaret = (sel.Count() == 1) && sel.Empty();
+ const SelectionPosition spCaret = sel.Last();
int delta = newPos.Position() - sel.MainCaret();
newPos = ClampPositionIntoDocument(newPos);
@@ -809,8 +813,7 @@ int Editor::MovePositionTo(SelectionPosition newPos, Selection::selTypes selt, b
if (!multipleSelection && sel.IsRectangular() && (selt == Selection::selStream)) {
// Can't turn into multiple selection so clear additional selections
InvalidateSelection(SelectionRange(newPos), true);
- SelectionRange rangeMain = sel.RangeMain();
- sel.SetSelection(rangeMain);
+ sel.DropAdditionalRanges();
}
if (!sel.IsRectangular() && (selt == Selection::selRectangle)) {
// Switching to rectangular
@@ -829,7 +832,7 @@ int Editor::MovePositionTo(SelectionPosition newPos, Selection::selTypes selt, b
}
ShowCaretAtCurrentPosition();
- int currentLine = pdoc->LineFromPosition(newPos.Position());
+ const int currentLine = pdoc->LineFromPosition(newPos.Position());
if (ensureVisible) {
// In case in need of wrapping to ensure DisplayFromDoc works.
if (currentLine >= wrapPending.start)
@@ -848,11 +851,10 @@ int Editor::MovePositionTo(SelectionPosition newPos, Selection::selTypes selt, b
if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) {
RedrawSelMargin();
}
- return 0;
}
-int Editor::MovePositionTo(int newPos, Selection::selTypes selt, bool ensureVisible) {
- return MovePositionTo(SelectionPosition(newPos), selt, ensureVisible);
+void Editor::MovePositionTo(int newPos, Selection::selTypes selt, bool ensureVisible) {
+ MovePositionTo(SelectionPosition(newPos), selt, ensureVisible);
}
SelectionPosition Editor::MovePositionSoVisible(SelectionPosition pos, int moveDir) {
@@ -1833,9 +1835,8 @@ void Editor::AddChar(char ch) {
void Editor::FilterSelections() {
if (!additionalSelectionTyping && (sel.Count() > 1)) {
- SelectionRange rangeOnly = sel.RangeMain();
- InvalidateSelection(rangeOnly, true);
- sel.SetSelection(rangeOnly);
+ InvalidateWholeSelection();
+ sel.DropAdditionalRanges();
}
}
@@ -2952,8 +2953,8 @@ void Editor::CancelModes() {
void Editor::NewLine() {
// Remove non-main ranges
- InvalidateSelection(sel.RangeMain(), true);
- sel.SetSelection(sel.RangeMain());
+ InvalidateWholeSelection();
+ sel.DropAdditionalRanges();
sel.RangeMain().ClearVirtualSpace();
// Clear main range and insert line end
@@ -3078,7 +3079,7 @@ int Editor::StartEndDisplayLine(int pos, bool start) {
int Editor::KeyCommand(unsigned int iMessage) {
switch (iMessage) {
case SCI_LINEDOWN:
- CursorUpOrDown(1);
+ CursorUpOrDown(1, Selection::noSel);
break;
case SCI_LINEDOWNEXTEND:
CursorUpOrDown(1, Selection::selStream);
@@ -3087,7 +3088,7 @@ int Editor::KeyCommand(unsigned int iMessage) {
CursorUpOrDown(1, Selection::selRectangle);
break;
case SCI_PARADOWN:
- ParaUpOrDown(1);
+ ParaUpOrDown(1, Selection::noSel);
break;
case SCI_PARADOWNEXTEND:
ParaUpOrDown(1, Selection::selStream);
@@ -3097,7 +3098,7 @@ int Editor::KeyCommand(unsigned int iMessage) {
MoveCaretInsideView(false);
break;
case SCI_LINEUP:
- CursorUpOrDown(-1);
+ CursorUpOrDown(-1, Selection::noSel);
break;
case SCI_LINEUPEXTEND:
CursorUpOrDown(-1, Selection::selStream);
@@ -3106,7 +3107,7 @@ int Editor::KeyCommand(unsigned int iMessage) {
CursorUpOrDown(-1, Selection::selRectangle);
break;
case SCI_PARAUP:
- ParaUpOrDown(-1);
+ ParaUpOrDown(-1, Selection::noSel);
break;
case SCI_PARAUPEXTEND:
ParaUpOrDown(-1, Selection::selStream);
@@ -3340,9 +3341,8 @@ int Editor::KeyCommand(unsigned int iMessage) {
CancelModes();
if (sel.Count() > 1) {
// Drop additional selections
- const SelectionRange rangeOnly = sel.RangeMain();
- InvalidateSelection(rangeOnly, true);
- sel.SetSelection(rangeOnly);
+ InvalidateWholeSelection();
+ sel.DropAdditionalRanges();
}
break;
case SCI_DELETEBACK:
@@ -3436,7 +3436,7 @@ int Editor::KeyCommand(unsigned int iMessage) {
break;
case SCI_DELWORDRIGHT: {
UndoGroup ug(pdoc);
- InvalidateSelection(sel.RangeMain(), true);
+ InvalidateWholeSelection();
sel.RangeMain().caret = SelectionPosition(
InsertSpace(sel.RangeMain().caret.Position(), sel.RangeMain().caret.VirtualSpace()));
sel.RangeMain().anchor = sel.RangeMain().caret;
@@ -3446,7 +3446,7 @@ int Editor::KeyCommand(unsigned int iMessage) {
break;
case SCI_DELWORDRIGHTEND: {
UndoGroup ug(pdoc);
- InvalidateSelection(sel.RangeMain(), true);
+ InvalidateWholeSelection();
sel.RangeMain().caret = SelectionPosition(
InsertSpace(sel.RangeMain().caret.Position(), sel.RangeMain().caret.VirtualSpace()));
int endWord = pdoc->NextWordEnd(sel.MainCaret(), 1);
@@ -4611,7 +4611,7 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) {
if (sel.Count() > 1) {
sel.RangeMain() =
SelectionRange(newPos, sel.Range(sel.Count() - 1).anchor);
- InvalidateSelection(sel.RangeMain(), true);
+ InvalidateWholeSelection();
} else {
SetSelection(newPos, sel.RangeMain().anchor);
}
@@ -7203,7 +7203,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::selStream));
sel.selType = Selection::selStream;
}
- InvalidateSelection(sel.RangeMain(), true);
+ InvalidateWholeSelection();
break;
}
case SCI_GETSELECTIONMODE:
@@ -7695,7 +7695,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_ROTATESELECTION:
sel.RotateMain();
- InvalidateSelection(sel.RangeMain(), true);
+ InvalidateWholeSelection();
break;
case SCI_SWAPMAINANCHORCARET:
diff --git a/src/Editor.h b/src/Editor.h
index b08fc7159..3301c4b05 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -313,6 +313,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void SetRectangularRange();
void ThinRectangularRange();
void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false);
+ void InvalidateWholeSelection();
void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_);
void SetSelection(int currentPos_, int anchor_);
void SetSelection(SelectionPosition currentPos_);
@@ -325,8 +326,8 @@ protected: // ScintillaBase subclass needs access to much of Editor
bool SelectionContainsProtected();
int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true) const;
SelectionPosition MovePositionOutsideChar(SelectionPosition pos, int moveDir, bool checkLineEnd=true) const;
- int MovePositionTo(SelectionPosition newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true);
- int MovePositionTo(int newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true);
+ void MovePositionTo(SelectionPosition newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true);
+ void MovePositionTo(int newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true);
SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir);
SelectionPosition MovePositionSoVisible(int pos, int moveDir);
Point PointMainCaret();
@@ -457,8 +458,8 @@ protected: // ScintillaBase subclass needs access to much of Editor
void Duplicate(bool forLine);
virtual void CancelModes();
void NewLine();
- void CursorUpOrDown(int direction, Selection::selTypes selt=Selection::noSel);
- void ParaUpOrDown(int direction, Selection::selTypes selt=Selection::noSel);
+ void CursorUpOrDown(int direction, Selection::selTypes selt);
+ void ParaUpOrDown(int direction, Selection::selTypes selt);
int StartEndDisplayLine(int pos, bool start);
virtual int KeyCommand(unsigned int iMessage);
virtual int KeyDefault(int /* key */, int /*modifiers*/);
diff --git a/src/Selection.cxx b/src/Selection.cxx
index 52ed5774e..f4308b130 100644
--- a/src/Selection.cxx
+++ b/src/Selection.cxx
@@ -343,6 +343,10 @@ void Selection::DropSelection(size_t r) {
}
}
+void Selection::DropAdditionalRanges() {
+ SetSelection(RangeMain());
+}
+
void Selection::TentativeSelection(SelectionRange range) {
if (!tentativeMain) {
rangesSaved = ranges;
diff --git a/src/Selection.h b/src/Selection.h
index 499f83771..166e3fa71 100644
--- a/src/Selection.h
+++ b/src/Selection.h
@@ -172,6 +172,7 @@ public:
void AddSelection(SelectionRange range);
void AddSelectionWithoutTrim(SelectionRange range);
void DropSelection(size_t r);
+ void DropAdditionalRanges();
void TentativeSelection(SelectionRange range);
void CommitTentative();
int CharacterInSelection(int posCharacter) const;