From 23b2a54292964dc653d7ebb64c4b2a044eeaa8e7 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 15 Mar 2022 15:14:42 +1100 Subject: Feature [feature-requests:#1431] Add SCI_GETSTYLEINDEXAT API to return styles over 127 as positive integers. --- call/ScintillaCall.cxx | 7 +++++-- doc/ScintillaDoc.html | 13 ++++++++++--- doc/ScintillaHistory.html | 4 ++++ include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ include/ScintillaCall.h | 1 + include/ScintillaMessages.h | 1 + src/Editor.cxx | 6 ++++++ test/simpleTests.py | 9 ++++++--- 9 files changed, 37 insertions(+), 8 deletions(-) diff --git a/call/ScintillaCall.cxx b/call/ScintillaCall.cxx index 53b4e0cf7..ec689a274 100644 --- a/call/ScintillaCall.cxx +++ b/call/ScintillaCall.cxx @@ -96,8 +96,7 @@ char ScintillaCall::CharacterAt(Position position) { } int ScintillaCall::UnsignedStyleAt(Position position) { - // Returns signed value but easier to use as unsigned - return static_cast(Call(Message::GetStyleAt, position)); + return static_cast(Call(Message::GetStyleIndexAt, position)); } std::string ScintillaCall::StringOfSpan(Span span) { @@ -192,6 +191,10 @@ int ScintillaCall::StyleAt(Position pos) { return static_cast(Call(Message::GetStyleAt, pos)); } +int ScintillaCall::StyleIndexAt(Position pos) { + return static_cast(Call(Message::GetStyleIndexAt, pos)); +} + void ScintillaCall::Redo() { Call(Message::Redo); } diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index c463dc3c2..782f299eb 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -129,7 +129,7 @@

Scintilla Documentation

-

Last edited 2 February 2021 NH

+

Last edited 9 March 2022 NH

Scintilla 5 has moved the lexers from Scintilla into a new Lexilla project.
@@ -543,6 +543,7 @@ SCI_CLEARDOCUMENTSTYLE
SCI_GETCHARAT(position pos) → int
SCI_GETSTYLEAT(position pos) → int
+ SCI_GETSTYLEINDEXAT(position pos) → int
SCI_GETSTYLEDTEXT(<unused>, Sci_TextRange *tr) → position
SCI_RELEASEALLEXTENDEDSTYLES
SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles) → int
@@ -694,9 +695,15 @@ This returns the character at pos in the document or 0 if pos is negative or past the end of the document.

-

SCI_GETSTYLEAT(position pos) → int
+

+ SCI_GETSTYLEAT(position pos) → int
+ SCI_GETSTYLEINDEXAT(position pos) → int
This returns the style at pos in the document, or 0 if pos is - negative or past the end of the document.

+ negative or past the end of the document. + SCI_GETSTYLEAT may return a negative number for styles over 127 whereas SCI_GETSTYLEINDEXAT + will only return positive numbers. + SCI_GETSTYLEINDEXAT should be preferred as it handles styles more consistently and may avoid problems + with lexers that define more than 128 styles.

SCI_RELEASEALLEXTENDEDSTYLES
SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles) → int
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index ba65ea3e2..544fcd11f 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -581,6 +581,10 @@ Released 24 February 2022.

  • + Add SCI_GETSTYLEINDEXAT API to return styles over 127 as positive integers. + Feature #1431. +
  • +
  • Fix crash with unexpected right-to-left text on GTK. Bug #2309.
  • diff --git a/include/Scintilla.h b/include/Scintilla.h index fbd2bf3f3..14f788eae 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -57,6 +57,7 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SCI_GETCURRENTPOS 2008 #define SCI_GETANCHOR 2009 #define SCI_GETSTYLEAT 2010 +#define SCI_GETSTYLEINDEXAT 2038 #define SCI_REDO 2011 #define SCI_SETUNDOCOLLECTION 2012 #define SCI_SELECTALL 2013 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 36d771402..7c20e9144 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -130,6 +130,9 @@ get position GetAnchor=2009(,) # Returns the style byte at the position. get int GetStyleAt=2010(position pos,) +# Returns the unsigned style byte at the position. +get int GetStyleIndexAt=2038(position pos,) + # Redoes the next action on the undo history. fun void Redo=2011(,) diff --git a/include/ScintillaCall.h b/include/ScintillaCall.h index 272345489..83e62d6da 100644 --- a/include/ScintillaCall.h +++ b/include/ScintillaCall.h @@ -88,6 +88,7 @@ public: Position CurrentPos(); Position Anchor(); int StyleAt(Position pos); + int StyleIndexAt(Position pos); void Redo(); void SetUndoCollection(bool collectUndo); void SelectAll(); diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h index 33a875f0a..d7bec7f75 100644 --- a/include/ScintillaMessages.h +++ b/include/ScintillaMessages.h @@ -28,6 +28,7 @@ enum class Message { GetCurrentPos = 2008, GetAnchor = 2009, GetStyleAt = 2010, + GetStyleIndexAt = 2038, Redo = 2011, SetUndoCollection = 2012, SelectAll = 2013, diff --git a/src/Editor.cxx b/src/Editor.cxx index bbac4862a..e7459e477 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6484,6 +6484,12 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { else return pdoc->StyleAt(PositionFromUPtr(wParam)); + case Message::GetStyleIndexAt: + if (PositionFromUPtr(wParam) >= pdoc->Length()) + return 0; + else + return pdoc->StyleIndexAt(PositionFromUPtr(wParam)); + case Message::Redo: Redo(); break; diff --git a/test/simpleTests.py b/test/simpleTests.py index 49b6061a4..7b326f8e0 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -48,13 +48,16 @@ class TestSimple(unittest.TestCase): def testAddStyledText(self): self.assertEquals(self.ed.EndStyled, 0) - self.ed.AddStyledText(2, b"x\002") - self.assertEquals(self.ed.Length, 1) + self.ed.AddStyledText(4, b"x\002y\377") + self.assertEquals(self.ed.Length, 2) self.assertEquals(self.ed.GetCharAt(0), ord("x")) self.assertEquals(self.ed.GetStyleAt(0), 2) + self.assertEquals(self.ed.GetStyleIndexAt(0), 2) + self.assertEquals(self.ed.GetStyleIndexAt(1), 255) self.assertEquals(self.ed.StyledTextRange(0, 1), b"x\002") + self.assertEquals(self.ed.StyledTextRange(1, 2), b"y\377") self.ed.ClearDocumentStyle() - self.assertEquals(self.ed.Length, 1) + self.assertEquals(self.ed.Length, 2) self.assertEquals(self.ed.GetCharAt(0), ord("x")) self.assertEquals(self.ed.GetStyleAt(0), 0) self.assertEquals(self.ed.StyledTextRange(0, 1), b"x\0") -- cgit v1.2.3