From 04cc53969e0d23cf19365712ca8c6afdbc4f3822 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 5 Nov 2023 14:08:57 +1100 Subject: Add SCI_SETMOVEEXTENDSSELECTION to simplify selection mode manipulation. --- call/ScintillaCall.cxx | 4 ++++ doc/ScintillaDoc.html | 10 +++++++--- doc/ScintillaHistory.html | 3 +++ include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ include/ScintillaCall.h | 1 + include/ScintillaMessages.h | 1 + src/Editor.cxx | 3 +++ test/simpleTests.py | 19 +++++++++++++++++++ 9 files changed, 42 insertions(+), 3 deletions(-) diff --git a/call/ScintillaCall.cxx b/call/ScintillaCall.cxx index dcffb8a7e..4981d6299 100644 --- a/call/ScintillaCall.cxx +++ b/call/ScintillaCall.cxx @@ -2367,6 +2367,10 @@ SelectionMode ScintillaCall::SelectionMode() { return static_cast(Call(Message::GetSelectionMode)); } +void ScintillaCall::SetMoveExtendsSelection(bool moveExtendsSelection) { + Call(Message::SetMoveExtendsSelection, moveExtendsSelection); +} + bool ScintillaCall::MoveExtendsSelection() { return Call(Message::GetMoveExtendsSelection); } diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index c0b80e793..43407a40b 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -129,7 +129,7 @@

Scintilla Documentation

-

Last edited 1 November 2023 NH

+

Last edited 5 November 2023 NH

Scintilla 5 has moved the lexers from Scintilla into a new Lexilla project.
@@ -980,6 +980,7 @@ struct Sci_TextRangeFull { SCI_SELECTIONISRECTANGLE → bool
SCI_SETSELECTIONMODE(int selectionMode)
SCI_GETSELECTIONMODE → int
+ SCI_SETMOVEEXTENDSSELECTION(bool moveExtendsSelection)
SCI_GETMOVEEXTENDSSELECTION → bool
SCI_GETLINESELSTARTPOSITION(line line) → position
SCI_GETLINESELENDPOSITION(line line) → position
@@ -1135,8 +1136,11 @@ struct Sci_TextRangeFull { SC_SEL_THIN is the mode after a rectangular selection has been typed into and ensures that no characters are selected.

-

SCI_GETMOVEEXTENDSSELECTION → bool
- This returns 1 if regular caret moves will extend or reduce the selection, 0 if not. +

+ SCI_SETMOVEEXTENDSSELECTION(bool moveExtendsSelection)
+ SCI_GETMOVEEXTENDSSELECTION → bool
+ This controls whether regular caret moves extends the selection leaving the anchor unchanged. + It is 1 if regular caret moves will extend or reduce the selection, 0 if not. SCI_SETSELECTIONMODE toggles this setting between on and off.

SCI_GETLINESELSTARTPOSITION(line line) → position
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 333121b42..f823ee0ef 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -591,6 +591,9 @@ Released 18 November 2023.

  • + Add SCI_SETMOVEEXTENDSSELECTION to simplify selection mode manipulation. +
  • +
  • Improve performance of global replace by reducing cache invalidation overhead. Feature #1502.
  • diff --git a/include/Scintilla.h b/include/Scintilla.h index 43a41e986..5b85dac47 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -875,6 +875,7 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SC_SEL_THIN 3 #define SCI_SETSELECTIONMODE 2422 #define SCI_GETSELECTIONMODE 2423 +#define SCI_SETMOVEEXTENDSSELECTION 2719 #define SCI_GETMOVEEXTENDSSELECTION 2706 #define SCI_GETLINESELSTARTPOSITION 2424 #define SCI_GETLINESELENDPOSITION 2425 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 9f02c78d2..b15606af0 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2362,6 +2362,9 @@ set void SetSelectionMode=2422(SelectionMode selectionMode,) # Get the mode of the current selection. get SelectionMode GetSelectionMode=2423(,) +# Set whether or not regular caret moves will extend or reduce the selection. +set void SetMoveExtendsSelection=2719(bool moveExtendsSelection,) + # Get whether or not regular caret moves will extend or reduce the selection. get bool GetMoveExtendsSelection=2706(,) diff --git a/include/ScintillaCall.h b/include/ScintillaCall.h index 8a01f2acb..0c95ef9e7 100644 --- a/include/ScintillaCall.h +++ b/include/ScintillaCall.h @@ -635,6 +635,7 @@ public: void CopyText(Position length, const char *text); void SetSelectionMode(Scintilla::SelectionMode selectionMode); Scintilla::SelectionMode SelectionMode(); + void SetMoveExtendsSelection(bool moveExtendsSelection); bool MoveExtendsSelection(); Position GetLineSelStartPosition(Line line); Position GetLineSelEndPosition(Line line); diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h index 12b2c2504..e45398d72 100644 --- a/include/ScintillaMessages.h +++ b/include/ScintillaMessages.h @@ -557,6 +557,7 @@ enum class Message { CopyText = 2420, SetSelectionMode = 2422, GetSelectionMode = 2423, + SetMoveExtendsSelection = 2719, GetMoveExtendsSelection = 2706, GetLineSelStartPosition = 2424, GetLineSelEndPosition = 2425, diff --git a/src/Editor.cxx b/src/Editor.cxx index 0b65041d2..ca7fe2e88 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -8226,6 +8226,9 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { default: // ?! return static_cast(SelectionMode::Stream); } + case Message::SetMoveExtendsSelection: + sel.SetMoveExtends(wParam != 0); + break; case Message::GetMoveExtendsSelection: return sel.MoveExtends(); case Message::GetLineSelStartPosition: diff --git a/test/simpleTests.py b/test/simpleTests.py index d372e0fbd..6f82c4004 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -2057,6 +2057,7 @@ class TestModalSelection(unittest.TestCase): self.assertEqual(self.ed.GetSelectionNAnchor(0), 1) self.ed.SelectionMode = self.ed.SC_SEL_STREAM self.assertEqual(self.ed.GetSelectionMode(), self.ed.SC_SEL_STREAM) + self.assertEqual(self.ed.MoveExtendsSelection, True) self.assertEqual(self.ed.Selections, 1) self.assertEqual(self.ed.MainSelection, 0) self.assertEqual(self.ed.GetSelectionNCaret(0), 1) @@ -2072,6 +2073,24 @@ class TestModalSelection(unittest.TestCase): self.assertEqual(self.ed.GetSelectionNCaret(0), 6) self.assertEqual(self.ed.GetSelectionNAnchor(0), 1) self.ed.ClearSelections() + + def testTurningOffMoveExtendsSelection(self): + self.ed.SetSelection(1, 1) + self.ed.SelectionMode = self.ed.SC_SEL_STREAM + self.ed.CharRight() + self.ed.LineDown() + self.assertEqual(self.ed.MoveExtendsSelection, True) + self.ed.MoveExtendsSelection = False + self.assertEqual(self.ed.MoveExtendsSelection, False) + self.ed.CharRight() + self.assertEqual(self.ed.Selections, 1) + self.assertEqual(self.ed.MainSelection, 0) + self.assertEqual(selectionRepresentation(self.ed, 0), "6-6") + self.ed.CharRight() + self.assertEqual(self.ed.Selections, 1) + self.assertEqual(self.ed.MainSelection, 0) + self.assertEqual(selectionRepresentation(self.ed, 0), "7-7") + self.ed.ClearSelections() def testRectangleSelection(self): self.ed.SetSelection(1, 1) -- cgit v1.2.3