From 60e0be1d49d4ba0e093a28bd3c2039f0c1ef8344 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 29 Oct 2023 09:25:20 +1100 Subject: Bug [#2078]. Fix rectangular selections with SCI_MOVESELECTEDLINESUP and SCI_MOVESELECTEDLINESDOWN. --- doc/ScintillaHistory.html | 4 ++++ src/Editor.cxx | 5 ++++- test/simpleTests.py | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 7d1d9f48f..d49ee81a0 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -599,6 +599,10 @@ Bug #2405.
  • + Make SCI_MOVESELECTEDLINESUP and SCI_MOVESELECTEDLINESDOWN work for rectangular selections. + Bug #2078. +
  • +
  • For Cocoa, fix invisible text on macOS 14 Sonoma. Bug #2402.
  • diff --git a/src/Editor.cxx b/src/Editor.cxx index ade5094f7..796279871 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -980,7 +980,10 @@ void Editor::VerticalCentreCaret() { void Editor::MoveSelectedLines(int lineDelta) { if (sel.IsRectangular()) { - return; + // Convert to stream selection + const SelectionRange rangeRectangular = sel.Rectangular(); + sel.Clear(); + sel.SetSelection(rangeRectangular); } // if selection doesn't start at the beginning of the line, set the new start diff --git a/test/simpleTests.py b/test/simpleTests.py index 653ab4338..d731ebbd6 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -668,6 +668,17 @@ class TestSimple(unittest.TestCase): self.ed.SetSel(1, 2) self.ed.MoveSelectedLinesDown() self.assertEqual(self.ed.Contents(), b"b2\na1\nc3") + + # Exercise rectangular selection + self.ed.EOLMode = self.ed.SC_EOL_LF + self.ed.SetContents(b"a1\nb2\nc3") + self.ed.RectangularSelectionAnchor = 1 + self.ed.RectangularSelectionCaret = 4 + # Check rectangular not stream + self.assertEqual(self.ed.GetSelectionMode(), self.ed.SC_SEL_RECTANGLE) + self.assertEqual(self.ed.Selections, 2) + self.ed.MoveSelectedLinesDown() + self.assertEqual(self.ed.Contents(), b"c3\na1\nb2") # Restore line end self.ed.EOLMode = lineEndType @@ -2044,6 +2055,7 @@ class TestModalSelection(unittest.TestCase): self.assertEqual(self.ed.GetSelectionNCaret(0), 1) 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.Selections, 1) self.assertEqual(self.ed.MainSelection, 0) self.assertEqual(self.ed.GetSelectionNCaret(0), 1) @@ -2067,6 +2079,7 @@ class TestModalSelection(unittest.TestCase): self.assertEqual(self.ed.GetSelectionNCaret(0), 1) self.assertEqual(self.ed.GetSelectionNAnchor(0), 1) self.ed.SelectionMode = self.ed.SC_SEL_RECTANGLE + self.assertEqual(self.ed.GetSelectionMode(), self.ed.SC_SEL_RECTANGLE) self.assertEqual(self.ed.Selections, 1) self.assertEqual(self.ed.MainSelection, 0) self.assertEqual(self.ed.GetSelectionNCaret(0), 1) @@ -2092,6 +2105,7 @@ class TestModalSelection(unittest.TestCase): self.assertEqual(self.ed.GetSelectionNCaret(0), 1) self.assertEqual(self.ed.GetSelectionNAnchor(0), 1) self.ed.SelectionMode = self.ed.SC_SEL_LINES + self.assertEqual(self.ed.GetSelectionMode(), self.ed.SC_SEL_LINES) self.assertEqual(self.ed.Selections, 1) self.assertEqual(self.ed.MainSelection, 0) self.assertEqual(self.ed.GetSelectionNCaret(0), 0) -- cgit v1.2.3