From 8aeb0e4b77a0f6905981df5f2d9c4622d55a12fb Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Wed, 15 Jul 2020 12:08:11 +1000 Subject: Feature [feature-requests:1368]. Add BraceMatchNext API. --- 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 f4dfb1e06..6128a6aa6 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -4006,6 +4006,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)
@@ -4041,6 +4042,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 f0e2dcca6..1d3f2c115 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -589,6 +589,10 @@ Bug #2184.

  • + 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 d3b6ac237..56f153f94 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -685,6 +685,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 b8d92da19..a1b0f58aa 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1876,6 +1876,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 dcb26acdf..95792fa1f 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -2657,7 +2657,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') @@ -2667,7 +2667,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 6e8507f04..37c37c4b8 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 45cc42804..28fa89120 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7646,7 +7646,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