From 9ec5dc184d3095ea6c091ecd326e459c7caf2ca7 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 9 Sep 2020 23:41:24 -0400 Subject: Backport: Feature [feature-requests:1350]. Add SCI_GETMULTIEDGECOLUMN. Backport of changeset 8507:e72e8cf58ea7. --- doc/ScintillaDoc.html | 7 ++++++- doc/ScintillaHistory.html | 6 ++++++ include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ src/Editor.cxx | 25 +++++++++++++++++++++---- test/simpleTests.py | 40 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 5 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 1a07a4032..feab651ee 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -6801,6 +6801,8 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
SCI_MULTIEDGEADDLINE(position column, colour edgeColour)
SCI_MULTIEDGECLEARALL
+ SCI_GETMULTIEDGECOLUMN(int which) +

SCI_SETEDGEMODE(int edgeMode)
@@ -6878,10 +6880,13 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){

SCI_MULTIEDGEADDLINE(position column, colour edgeColour)
SCI_MULTIEDGECLEARALL
+ SCI_GETMULTIEDGECOLUMN(int which)
SCI_MULTIEDGEADDLINE adds a new vertical edge to the view. The edge will be displayed at the given column number. The resulting edge position depends on the metric of a space character in STYLE_DEFAULT. All the edges can be cleared with - SCI_MULTIEDGECLEARALL.

+ SCI_MULTIEDGECLEARALL. SCI_GETMULTIEDGECOLUMN returns the column of the + Nth vertical edge (indexed from 0). If which is greater or equal + to the number of vertical edges, this returns -1.

Accessibility

diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 8ab756144..c0eb117a7 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -550,6 +550,8 @@ Hugues Larrive Prakash Sahni uhf7 + + Derek Brown

@@ -597,6 +599,10 @@ Fixed bug where layout caching was ineffective. Bug #2197. +

  • + Added method for iterating through multiple vertical edges: SCI_GETMULTIEDGECOLUMN. + Feature #1350. +
  • Release 3.21.0 diff --git a/include/Scintilla.h b/include/Scintilla.h index 32012c5f6..6f59d4e27 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -705,6 +705,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETEDGECOLOUR 2365 #define SCI_MULTIEDGEADDLINE 2694 #define SCI_MULTIEDGECLEARALL 2695 +#define SCI_GETMULTIEDGECOLUMN 2749 #define SCI_SEARCHANCHOR 2366 #define SCI_SEARCHNEXT 2367 #define SCI_SEARCHPREV 2368 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index fb31e5b73..7d32ed46d 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1935,6 +1935,9 @@ fun void MultiEdgeAddLine=2694(position column, colour edgeColour) # Clear all vertical edges. fun void MultiEdgeClearAll=2695(,) +# Get multi edge positions. +get position GetMultiEdgeColumn=2749(int which,) + # Sets the current caret position to be the search anchor. fun void SearchAnchor=2366(,) diff --git a/src/Editor.cxx b/src/Editor.cxx index 4256bb817..8453118b3 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7690,16 +7690,33 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { InvalidateStyleRedraw(); break; - case SCI_MULTIEDGEADDLINE: - vs.theMultiEdge.push_back(EdgeProperties(wParam, lParam)); - InvalidateStyleRedraw(); - break; + case SCI_MULTIEDGEADDLINE: { + // Insert new edge in sorted order. + const int column = static_cast(wParam); + vs.theMultiEdge.insert( + std::upper_bound(vs.theMultiEdge.begin(), vs.theMultiEdge.end(), column, + [](const EdgeProperties &a, const EdgeProperties &b) { + return a.column < b.column; + }), + EdgeProperties(wParam, lParam)); + InvalidateStyleRedraw(); + break; + } case SCI_MULTIEDGECLEARALL: std::vector().swap(vs.theMultiEdge); // Free vector and memory, C++03 compatible InvalidateStyleRedraw(); break; + case SCI_GETMULTIEDGECOLUMN: { + const size_t which = wParam; + // size_t is unsigned so this also handles negative inputs. + if (which >= vs.theMultiEdge.size()) { + return -1; + } + return vs.theMultiEdge[which].column; + } + case SCI_GETACCESSIBILITY: return SC_ACCESSIBILITY_DISABLED; diff --git a/test/simpleTests.py b/test/simpleTests.py index 7b4bfcaf2..0e39ec55d 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -2318,6 +2318,46 @@ class TestCallTip(unittest.TestCase): self.ed.CallTipCancel() self.assertEquals(self.ed.CallTipActive(), 0) +class TestEdge(unittest.TestCase): + + def setUp(self): + self.xite = Xite.xiteFrame + self.ed = self.xite.ed + self.ed.ClearAll() + + def testBasics(self): + self.ed.EdgeColumn = 3 + self.assertEquals(self.ed.EdgeColumn, 3) + self.ed.SetEdgeColour(0xA0) + self.assertEquals(self.ed.GetEdgeColour(), 0xA0) + + def testMulti(self): + self.assertEquals(self.ed.GetMultiEdgeColumn(-1), -1) + self.assertEquals(self.ed.GetMultiEdgeColumn(0), -1) + self.ed.MultiEdgeAddLine(5, 0x50) + self.assertEquals(self.ed.GetMultiEdgeColumn(0), 5) + self.assertEquals(self.ed.GetMultiEdgeColumn(1), -1) + self.ed.MultiEdgeAddLine(6, 0x60) + self.assertEquals(self.ed.GetMultiEdgeColumn(0), 5) + self.assertEquals(self.ed.GetMultiEdgeColumn(1), 6) + self.assertEquals(self.ed.GetMultiEdgeColumn(2), -1) + self.ed.MultiEdgeAddLine(4, 0x40) + self.assertEquals(self.ed.GetMultiEdgeColumn(0), 4) + self.assertEquals(self.ed.GetMultiEdgeColumn(1), 5) + self.assertEquals(self.ed.GetMultiEdgeColumn(2), 6) + self.assertEquals(self.ed.GetMultiEdgeColumn(3), -1) + self.ed.MultiEdgeClearAll() + self.assertEquals(self.ed.GetMultiEdgeColumn(0), -1) + + def testSameTwice(self): + # Tests that adding a column twice retains both + self.ed.MultiEdgeAddLine(5, 0x50) + self.ed.MultiEdgeAddLine(5, 0x55) + self.assertEquals(self.ed.GetMultiEdgeColumn(0), 5) + self.assertEquals(self.ed.GetMultiEdgeColumn(1), 5) + self.assertEquals(self.ed.GetMultiEdgeColumn(2), -1) + self.ed.MultiEdgeClearAll() + class TestAutoComplete(unittest.TestCase): def setUp(self): -- cgit v1.2.3