From 8cedd574bc15453d86926a71f9a8197dc5fdb5ee Mon Sep 17 00:00:00 2001 From: Michael Heath Date: Mon, 28 Nov 2022 17:59:01 +1100 Subject: Bug [#2363]. Change 'paragraph up' commands SCI_PARAUP and SCI_PARAUPEXTEND to go to the start position of the paragraph containing the caret. Only if the caret is already at the start of the paragraph will it go to the start of the previous paragraph. --- doc/ScintillaHistory.html | 8 ++++++++ src/Document.cxx | 5 ++++- test/simpleTests.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 2f9cf9d82..8bcd84c4b 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -574,6 +574,7 @@ Reinhard Nißl Ferdinand Oeinck + Michael Heath

Releases

@@ -602,6 +603,13 @@ Feature #1459.
  • + Change 'paragraph up' commands SCI_PARAUP and SCI_PARAUPEXTEND to + go to the start position of the paragraph containing the caret. + Only if the caret is already at the start of the paragraph will it go to the start + of the previous paragraph. + Bug #2363. +
  • +
  • On Win32, avoid blurry display with DirectWrite in GDI scaling mode. Bug #2344.
  • diff --git a/src/Document.cxx b/src/Document.cxx index c67aae125..7afe10701 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1772,7 +1772,10 @@ bool Document::IsWhiteLine(Sci::Line line) const { Sci::Position Document::ParaUp(Sci::Position pos) const { Sci::Line line = SciLineFromPosition(pos); - line--; + const Sci::Position start = LineStart(line); + if (pos == start) { + line--; + } while (line >= 0 && IsWhiteLine(line)) { // skip empty lines line--; } diff --git a/test/simpleTests.py b/test/simpleTests.py index 31ae42535..a16b940fd 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -1021,6 +1021,46 @@ class TestKeyCommands(unittest.TestCase): self.ed.DocumentEndExtend() self.assertEquals(self.selRange(), (10, 3)) + def testParagraphMove(self): + example = b"a\n\nbig\n\n\n\nboat" + self.ed.AddText(len(example), example) + start1 = 0 # Before 'a' + start2 = 3 # Before 'big' + start3 = 10 # Before 'boat' + + # Paragraph 2 to 1 + self.ed.SetSel(start2, start2) + self.ed.ParaUp() + self.assertEquals(self.selRange(), (start1, start1)) + self.ed.ParaDown() + self.assertEquals(self.selRange(), (start2, start2)) + self.ed.SetSel(start2, start2) + self.ed.ParaUpExtend() + self.assertEquals(self.selRange(), (start1, start2)) + self.ed.ParaDownExtend() + self.assertEquals(self.selRange(), (start2, start2)) + + # Inside paragraph 2 to start paragraph 2 + mid2 = start2+1 + self.ed.SetSel(mid2, mid2) + # Next line behaved differently before change for bug #2363 + self.ed.ParaUp() + self.assertEquals(self.selRange(), (start2, start2)) + self.ed.ParaDown() + self.assertEquals(self.selRange(), (start3, start3)) + self.ed.SetSel(mid2, mid2) + self.ed.ParaUpExtend() + self.assertEquals(self.selRange(), (start2, mid2)) + self.ed.ParaDownExtend() + self.assertEquals(self.selRange(), (start3, mid2)) + + # Paragraph 3 to 2 + self.ed.SetSel(start3, start3) + self.ed.ParaUp() + self.assertEquals(self.selRange(), (start2, start2)) + self.ed.ParaDown() + self.assertEquals(self.selRange(), (start3, start3)) + class TestMarkers(unittest.TestCase): -- cgit v1.2.3