From c47a76507f5bfd812604504d3b0246fa45be799e Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Wed, 15 Jul 2020 12:08:11 +1000 Subject: Backport: Feature [feature-requests:1368]. Add BraceMatchNext API. Backport of changeset 8406:a2ce85a55dfa. --- doc/ScintillaDoc.html | 5 +++++ doc/ScintillaHistory.html | 4 ++++ include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ src/Document.cxx | 4 ++-- src/Document.h | 2 +- src/Editor.cxx | 5 ++++- 7 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index ece36a4e2..1a07a4032 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3951,6 +3951,7 @@ struct Sci_TextToFind { SCI_BRACEHIGHLIGHTINDICATOR(bool useSetting, int indicator)
SCI_BRACEBADLIGHTINDICATOR(bool useSetting, int indicator)
SCI_BRACEMATCH(position pos, int maxReStyle) → position
+ SCI_BRACEMATCHNEXT(position pos, position startPos) → position

SCI_BRACEHIGHLIGHT(position posA, position posB)
@@ -3986,6 +3987,10 @@ struct Sci_TextToFind { maxReStyle parameter must currently be 0 - it may be used in the future to limit the length of brace searches.

+

SCI_BRACEMATCHNEXT(position pos, position startPos) → position
+ Similar to SCI_BRACEMATCH, but matching starts at the explicit start position startPos + instead of the implicitly next position pos ± 1.

+

Tabs and Indentation Guides

Indentation (the white space at the start of a line) is often used by programmers to clarify diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index a3dea460e..c7d4322fc 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -586,6 +586,10 @@ Bug #2141.

  • + Add SCI_BRACEMATCHNEXT API. + Feature #1368. +
  • +
  • Round SCI_TEXTWIDTH instead of truncating as this may be more accurate when sizing application elements to match text. Feature #1355. diff --git a/include/Scintilla.h b/include/Scintilla.h index 7eaef9be8..32012c5f6 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -687,6 +687,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_BRACEBADLIGHT 2352 #define SCI_BRACEBADLIGHTINDICATOR 2499 #define SCI_BRACEMATCH 2353 +#define SCI_BRACEMATCHNEXT 2369 #define SCI_GETVIEWEOL 2355 #define SCI_SETVIEWEOL 2356 #define SCI_GETDOCPOINTER 2357 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 29b5a2ac6..fb31e5b73 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1883,6 +1883,9 @@ fun void BraceBadLightIndicator=2499(bool useSetting, int indicator) # The maxReStyle must be 0 for now. It may be defined in a future release. fun position BraceMatch=2353(position pos, int maxReStyle) +# Similar to BraceMatch, but matching starts at the explicit start position. +fun position BraceMatchNext=2369(position pos, position startPos) + # Are the end of line characters visible? get bool GetViewEOL=2355(,) diff --git a/src/Document.cxx b/src/Document.cxx index 3143e7e1f..a9daf9339 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -2660,7 +2660,7 @@ static char BraceOpposite(char ch) noexcept { } // TODO: should be able to extend styled region to find matching brace -Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxReStyle*/) noexcept { +Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxReStyle*/, Sci::Position startPos, bool useStartPos) noexcept { const char chBrace = CharAt(position); const char chSeek = BraceOpposite(chBrace); if (chSeek == '\0') @@ -2670,7 +2670,7 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') direction = 1; int depth = 1; - position = NextPosition(position, direction); + position = useStartPos ? startPos : NextPosition(position, direction); while ((position >= 0) && (position < LengthNoExcept())) { const char chAtPos = CharAt(position); const int styAtPos = StyleIndexAt(position); diff --git a/src/Document.h b/src/Document.h index a9c591cb1..57dcd6e36 100644 --- a/src/Document.h +++ b/src/Document.h @@ -501,7 +501,7 @@ public: Sci::Position ParaUp(Sci::Position pos) const; Sci::Position ParaDown(Sci::Position pos) const; int IndentSize() const noexcept { return actualIndentInChars; } - Sci::Position BraceMatch(Sci::Position position, Sci::Position maxReStyle) noexcept; + Sci::Position BraceMatch(Sci::Position position, Sci::Position maxReStyle, Sci::Position startPos, bool useStartPos) noexcept; private: void NotifyModifyAttempt(); diff --git a/src/Editor.cxx b/src/Editor.cxx index 104f6d500..630a6f69e 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7632,7 +7632,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_BRACEMATCH: // wParam is position of char to find brace for, // lParam is maximum amount of text to restyle to find it - return pdoc->BraceMatch(static_cast(wParam), lParam); + return pdoc->BraceMatch(static_cast(wParam), lParam, 0, false); + + case SCI_BRACEMATCHNEXT: + return pdoc->BraceMatch(static_cast(wParam), 0, lParam, true); case SCI_GETVIEWEOL: return vs.viewEOL; -- cgit v1.2.3