aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2022-03-15 15:14:42 +1100
committerNeil <nyamatongwe@gmail.com>2022-03-15 15:14:42 +1100
commit23b2a54292964dc653d7ebb64c4b2a044eeaa8e7 (patch)
treefb9ccd4793daaa16b18551fd599b622f0ae96315
parent96480716cb3acc793436ce037650445a137115da (diff)
downloadscintilla-mirror-23b2a54292964dc653d7ebb64c4b2a044eeaa8e7.tar.gz
Feature [feature-requests:#1431] Add SCI_GETSTYLEINDEXAT API to return styles
over 127 as positive integers.
-rw-r--r--call/ScintillaCall.cxx7
-rw-r--r--doc/ScintillaDoc.html13
-rw-r--r--doc/ScintillaHistory.html4
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface3
-rw-r--r--include/ScintillaCall.h1
-rw-r--r--include/ScintillaMessages.h1
-rw-r--r--src/Editor.cxx6
-rw-r--r--test/simpleTests.py9
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<unsigned char>(Call(Message::GetStyleAt, position));
+ return static_cast<int>(Call(Message::GetStyleIndexAt, position));
}
std::string ScintillaCall::StringOfSpan(Span span) {
@@ -192,6 +191,10 @@ int ScintillaCall::StyleAt(Position pos) {
return static_cast<int>(Call(Message::GetStyleAt, pos));
}
+int ScintillaCall::StyleIndexAt(Position pos) {
+ return static_cast<int>(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 @@
<h1>Scintilla Documentation</h1>
- <p>Last edited 2 February 2021 NH</p>
+ <p>Last edited 9 March 2022 NH</p>
<p style="background:#90F0C0">Scintilla 5 has moved the lexers from Scintilla into a new
<a href="Lexilla.html">Lexilla</a> project.<br />
@@ -543,6 +543,7 @@
<a class="message" href="#SCI_CLEARDOCUMENTSTYLE">SCI_CLEARDOCUMENTSTYLE</a><br />
<a class="message" href="#SCI_GETCHARAT">SCI_GETCHARAT(position pos) &rarr; int</a><br />
<a class="message" href="#SCI_GETSTYLEAT">SCI_GETSTYLEAT(position pos) &rarr; int</a><br />
+ <a class="message" href="#SCI_GETSTYLEINDEXAT">SCI_GETSTYLEINDEXAT(position pos) &rarr; int</a><br />
<a class="message" href="#SCI_GETSTYLEDTEXT">SCI_GETSTYLEDTEXT(&lt;unused&gt;, Sci_TextRange *tr) &rarr; position</a><br />
<a class="message" href="#SCI_RELEASEALLEXTENDEDSTYLES">SCI_RELEASEALLEXTENDEDSTYLES</a><br />
<a class="message" href="#SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles) &rarr; int</a><br />
@@ -694,9 +695,15 @@
This returns the character at <code class="parameter">pos</code> in the document or 0 if <code class="parameter">pos</code> is
negative or past the end of the document.</p>
- <p><b id="SCI_GETSTYLEAT">SCI_GETSTYLEAT(position pos) &rarr; int</b><br />
+ <p>
+ <b id="SCI_GETSTYLEAT">SCI_GETSTYLEAT(position pos) &rarr; int</b><br />
+ <b id="SCI_GETSTYLEINDEXAT">SCI_GETSTYLEINDEXAT(position pos) &rarr; int</b><br />
This returns the style at <code class="parameter">pos</code> in the document, or 0 if <code class="parameter">pos</code> is
- negative or past the end of the document.</p>
+ negative or past the end of the document.
+ <code>SCI_GETSTYLEAT</code> may return a negative number for styles over 127 whereas <code>SCI_GETSTYLEINDEXAT</code>
+ will only return positive numbers.
+ <code>SCI_GETSTYLEINDEXAT</code> should be preferred as it handles styles more consistently and may avoid problems
+ with lexers that define more than 128 styles.</p>
<p><b id="SCI_RELEASEALLEXTENDEDSTYLES">SCI_RELEASEALLEXTENDEDSTYLES</b><br />
<b id="SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles) &rarr; int</b><br />
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.
</li>
<li>
+ Add SCI_GETSTYLEINDEXAT API to return styles over 127 as positive integers.
+ <a href="https://sourceforge.net/p/scintilla/feature-requests/1431/">Feature #1431</a>.
+ </li>
+ <li>
Fix crash with unexpected right-to-left text on GTK.
<a href="https://sourceforge.net/p/scintilla/bugs/2309/">Bug #2309</a>.
</li>
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")