diff options
-rw-r--r-- | doc/ScintillaDoc.html | 8 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 5 | ||||
-rw-r--r-- | include/Scintilla.h | 2 | ||||
-rw-r--r-- | include/Scintilla.iface | 8 | ||||
-rw-r--r-- | src/Document.cxx | 8 | ||||
-rw-r--r-- | src/Document.h | 2 | ||||
-rw-r--r-- | src/Editor.cxx | 6 | ||||
-rw-r--r-- | src/PerLine.cxx | 25 | ||||
-rw-r--r-- | src/PerLine.h | 3 | ||||
-rw-r--r-- | test/simpleTests.py | 39 |
10 files changed, 103 insertions, 3 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 8afdbbe98..1bd27d469 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -4147,6 +4147,8 @@ struct Sci_TextToFind { <a class="message" href="#SCI_MARKERPREVIOUS">SCI_MARKERPREVIOUS(line lineStart, int markerMask) → line</a><br /> <a class="message" href="#SCI_MARKERLINEFROMHANDLE">SCI_MARKERLINEFROMHANDLE(int markerHandle) → line</a><br /> <a class="message" href="#SCI_MARKERDELETEHANDLE">SCI_MARKERDELETEHANDLE(int markerHandle)</a><br /> + <a class="message" href="#SCI_MARKERHANDLEFROMLINE">SCI_MARKERHANDLEFROMLINE(line line, int which) → int</a><br /> + <a class="message" href="#SCI_MARKERNUMBERFROMLINE">SCI_MARKERNUMBERFROMLINE(line line, int which) → int</a><br /> </code> <p><b id="SCI_MARKERDEFINE">SCI_MARKERDEFINE(int markerNumber, int markerSymbol)</b><br /> @@ -4414,6 +4416,12 @@ struct Sci_TextToFind { class="message" href="#SCI_MARKERADD"><code>SCI_MARKERADD</code></a>. This function searches the document for the marker with this handle and deletes the marker if it is found.</p> + <p><b id="SCI_MARKERHANDLEFROMLINE">SCI_MARKERHANDLEFROMLINE(line line, int which) → int</b><br /> + <b id="SCI_MARKERNUMBERFROMLINE">SCI_MARKERNUMBERFROMLINE(line line, int which) → int</b><br /> + These messages returns the Nth marker handle or marker number in a given <code class="parameter">line</code>. + Handles are returned by <a class="message" href="#SCI_MARKERADD"><code>SCI_MARKERADD</code></a>. + If <code class="parameter">which</code> is greater or equal to the number of markers on a line, this returns -1;</p> + <h2 id="Indicators">Indicators</h2> <p>Indicators are used to display additional information over the top of styling. diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 201b2213a..49a0ca0e0 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -573,6 +573,11 @@ Added Visual Studio project files for Lexilla and Scintilla with no lexers. </li> <li> + Add methods for iterating through the marker handles and marker numbers on a line: + SCI_MARKERHANDLEFROMLINE and SCI_MARKERNUMBERFROMLINE. + <a href="https://sourceforge.net/p/scintilla/feature-requests/1344/">Feature #1344</a>. + </li> + <li> Fix brace styling in Batch lexer so that brace matching works. <a href="https://sourceforge.net/p/scintilla/bugs/1624/">Bug #1624</a>, <a href="https://sourceforge.net/p/scintilla/bugs/1906/">Bug #1906</a>, diff --git a/include/Scintilla.h b/include/Scintilla.h index 226d7c0ca..4f5be6427 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -63,6 +63,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_CANREDO 2016 #define SCI_MARKERLINEFROMHANDLE 2017 #define SCI_MARKERDELETEHANDLE 2018 +#define SCI_MARKERHANDLEFROMLINE 2732 +#define SCI_MARKERNUMBERFROMLINE 2733 #define SCI_GETUNDOCOLLECTION 2019 #define SCWS_INVISIBLE 0 #define SCWS_VISIBLEALWAYS 1 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 8e52f40f7..6e229bf37 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -156,6 +156,12 @@ fun line MarkerLineFromHandle=2017(int markerHandle,) # Delete a marker. fun void MarkerDeleteHandle=2018(int markerHandle,) +# Retrieve marker handles of a line +fun int MarkerHandleFromLine=2732(line line, int which) + +# Retrieve marker number of a marker handle +fun int MarkerNumberFromLine=2733(line line, int which) + # Is undo history being collected? get bool GetUndoCollection=2019(,) @@ -1242,6 +1248,8 @@ set void SetTargetEndVirtualSpace=2730(position space,) # Get the virtual space of the target end get position GetTargetEndVirtualSpace=2731(,) + + # Sets both the start and end of the target in one call. fun void SetTargetRange=2686(position start, position end) diff --git a/src/Document.cxx b/src/Document.cxx index 6b93a30af..263e83d7a 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -369,6 +369,14 @@ Sci::Line Document::LineFromHandle(int markerHandle) const { return Markers()->LineFromHandle(markerHandle); } +int Document::MarkerNumberFromLine(Sci::Line line, int which) const { + return Markers()->NumberFromLine(line, which); +} + +int Document::MarkerHandleFromLine(Sci::Line line, int which) const { + return Markers()->HandleFromLine(line, which); +} + Sci_Position SCI_METHOD Document::LineStart(Sci_Position line) const { return cb.LineStart(line); } diff --git a/src/Document.h b/src/Document.h index c96fe9ee7..1f03dda1d 100644 --- a/src/Document.h +++ b/src/Document.h @@ -403,6 +403,8 @@ public: void DeleteMarkFromHandle(int markerHandle); void DeleteAllMarks(int markerNum); Sci::Line LineFromHandle(int markerHandle) const; + int MarkerNumberFromLine(Sci::Line line, int which) const; + int MarkerHandleFromLine(Sci::Line line, int which) const; Sci_Position SCI_METHOD LineStart(Sci_Position line) const override; bool IsLineStartPosition(Sci::Position position) const; Sci_Position SCI_METHOD LineEnd(Sci_Position line) const override; diff --git a/src/Editor.cxx b/src/Editor.cxx index efb360331..b7636adb2 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6412,6 +6412,12 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { pdoc->DeleteMarkFromHandle(static_cast<int>(wParam)); break; + case SCI_MARKERHANDLEFROMLINE: + return pdoc->MarkerHandleFromLine(static_cast<Sci::Line>(wParam), static_cast<int>(lParam)); + + case SCI_MARKERNUMBERFROMLINE: + return pdoc->MarkerNumberFromLine(static_cast<Sci::Line>(wParam), static_cast<int>(lParam)); + case SCI_GETVIEWWS: return vs.viewWhitespace; diff --git a/src/PerLine.cxx b/src/PerLine.cxx index 017eb77b8..31da695ad 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -55,6 +55,15 @@ bool MarkerHandleSet::Contains(int handle) const noexcept { return false; } +MarkerHandleNumber const *MarkerHandleSet::GetMarkerHandleNumber(int which) const noexcept { + for (const MarkerHandleNumber &mhn : mhList) { + if (which == 0) + return &mhn; + which--; + } + return nullptr; +} + bool MarkerHandleSet::InsertHandle(int handle, int markerNum) { mhList.push_front(MarkerHandleNumber(handle, markerNum)); return true; @@ -116,6 +125,22 @@ Sci::Line LineMarkers::LineFromHandle(int markerHandle) { return -1; } +int LineMarkers::HandleFromLine(Sci::Line line, int which) const { + if (markers.Length() && (line >= 0) && (line < markers.Length()) && markers[line]) { + MarkerHandleNumber const *pnmh = markers[line]->GetMarkerHandleNumber(which); + return pnmh ? pnmh->handle : -1; + } + return -1; +} + +int LineMarkers::NumberFromLine(Sci::Line line, int which) const { + if (markers.Length() && (line >= 0) && (line < markers.Length()) && markers[line]) { + MarkerHandleNumber const *pnmh = markers[line]->GetMarkerHandleNumber(which); + return pnmh ? pnmh->number : -1; + } + return -1; +} + void LineMarkers::MergeMarkers(Sci::Line line) { if (markers[line + 1]) { if (!markers[line]) diff --git a/src/PerLine.h b/src/PerLine.h index 94dc17a20..3da02b5e5 100644 --- a/src/PerLine.h +++ b/src/PerLine.h @@ -41,6 +41,7 @@ public: void RemoveHandle(int handle); bool RemoveNumber(int markerNum, bool all); void CombineWith(MarkerHandleSet *other); + MarkerHandleNumber const *GetMarkerHandleNumber(int which) const noexcept; }; class LineMarkers : public PerLine { @@ -67,6 +68,8 @@ public: bool DeleteMark(Sci::Line line, int markerNum, bool all); void DeleteMarkFromHandle(int markerHandle); Sci::Line LineFromHandle(int markerHandle); + int HandleFromLine(Sci::Line line, int which) const; + int NumberFromLine(Sci::Line line, int which) const; }; class LineLevels : public PerLine { diff --git a/test/simpleTests.py b/test/simpleTests.py index 1ede72da3..7b4bfcaf2 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -1000,6 +1000,39 @@ class TestMarkers(unittest.TestCase): self.ed.MarkerDefine(1,3) self.assertEquals(self.ed.MarkerSymbolDefined(1), 3) + def markerFromLineIndex(self, line, index): + """ Helper that returns (handle, number) """ + return (self.ed.MarkerHandleFromLine(line, index), self.ed.MarkerNumberFromLine(line, index)) + + def markerSetFromLine(self, line): + """ Helper that returns set of (handle, number) """ + markerSet = set() + index = 0 + while 1: + marker = self.markerFromLineIndex(line, index) + if marker[0] == -1: + return markerSet + markerSet.add(marker) + index += 1 + + def testMarkerFromLine(self): + self.assertEquals(self.ed.MarkerHandleFromLine(1, 0), -1) + self.assertEquals(self.ed.MarkerNumberFromLine(1, 0), -1) + self.assertEquals(self.markerFromLineIndex(1, 0), (-1, -1)) + self.assertEquals(self.markerSetFromLine(1), set()) + + handle = self.ed.MarkerAdd(1,10) + self.assertEquals(self.markerFromLineIndex(1, 0), (handle, 10)) + self.assertEquals(self.markerFromLineIndex(1, 1), (-1, -1)) + self.assertEquals(self.markerSetFromLine(1), {(handle, 10)}) + + handle2 = self.ed.MarkerAdd(1,11) + # Don't want to depend on ordering so check as sets + self.assertEquals(self.markerSetFromLine(1), {(handle, 10), (handle2, 11)}) + + self.ed.MarkerDeleteHandle(handle2) + self.assertEquals(self.markerSetFromLine(1), {(handle, 10)}) + class TestIndicators(unittest.TestCase): def setUp(self): @@ -1053,7 +1086,7 @@ class TestIndicators(unittest.TestCase): def testIndicatorMovement(self): # Create a two character indicator over "BC" in "aBCd" and ensure that it doesn't - # leak onto surrounding characters when insertions made at either end but + # leak onto surrounding characters when insertions made at either end but # insertion inside indicator does extend length self.ed.InsertText(0, b"aBCd") self.ed.IndicatorCurrent = 3 @@ -1398,7 +1431,7 @@ class TestMultiSelection(unittest.TestCase): # 3 lines of 3 characters t = b"xxx\nxxx\nxxx" self.ed.AddText(len(t), t) - + def textOfSelection(self, n): self.ed.TargetStart = self.ed.GetSelectionNStart(n) self.ed.TargetEnd = self.ed.GetSelectionNEnd(n) @@ -1605,7 +1638,7 @@ class TestMultiSelection(unittest.TestCase): self.assertEquals(self.ed.Selections, 2) self.assertEquals(self.textOfSelection(0), texts[1]) self.assertEquals(self.textOfSelection(1), texts[0]) - + def selectionRepresentation(self, n): anchor = (self.ed.GetSelectionNAnchor(0), self.ed.GetSelectionNAnchorVirtualSpace(0)) caret = (self.ed.GetSelectionNCaret(0), self.ed.GetSelectionNCaretVirtualSpace(0)) |