From 2117f9e7b583e9093b6b297f8782027098320496 Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Tue, 25 Aug 2020 09:25:01 +1000 Subject: Feature [feature-requests:1350]. Add SCI_GETMULTIEDGECOLUMN. --- doc/ScintillaDoc.html | 7 ++++++- doc/ScintillaHistory.html | 5 +++++ include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ src/Editor.cxx | 25 +++++++++++++++++++++---- test/simpleTests.py | 40 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 5 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 6128a6aa6..d4bea6b60 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -6856,6 +6856,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)
@@ -6933,10 +6935,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 f5b952d0a..dc9311761 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -560,6 +560,7 @@ Michel Sauvard uhf7 gnombat + Derek Brown

@@ -624,6 +625,10 @@ caused continuing failures to find functions after the syntax error was corrected. Bug #2176. +

  • + Added method for iterating through multiple vertical edges: SCI_GETMULTIEDGECOLUMN. + Feature #1350. +
  • Release 4.4.4 diff --git a/include/Scintilla.h b/include/Scintilla.h index 56f153f94..acde9a5f9 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -703,6 +703,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 a1b0f58aa..2c044d1a8 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1928,6 +1928,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 5e9c0b673..cfd9e150e 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7704,16 +7704,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 6620968ad..f1ba906c5 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -2319,6 +2319,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