aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2023-02-13 14:02:40 +1100
committerNeil <nyamatongwe@gmail.com>2023-02-13 14:02:40 +1100
commit7179a3d6db03425155b56141a15b76e80fd30efa (patch)
treea0535ab6040aa9a4497df6907178d020d31528c3
parent80a1e22a987c4e749dd03500edc3ac4e189537c5 (diff)
downloadscintilla-mirror-7179a3d6db03425155b56141a15b76e80fd30efa.tar.gz
Where a multi-byte character contains multiple styles, display each byte as a
representation. This makes it easier to see and fix lexers that change styles mid-character, commonly because they use fixed size buffers.
-rw-r--r--doc/ScintillaHistory.html5
-rw-r--r--src/PositionCache.cxx16
2 files changed, 21 insertions, 0 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 52bc2d610..4050ea5cc 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -593,6 +593,11 @@
<li>
Fix clipping of line end wrap symbol for SC_WRAPVISUALFLAGLOC_END_BY_TEXT.
</li>
+ <li>
+ Where a multi-byte character contains multiple styles, display each byte as a representation.
+ This makes it easier to see and fix lexers that change styles mid-character, commonly because
+ they use fixed size buffers.
+ </li>
</ul>
<h3>
<a href="https://www.scintilla.org/scintilla533.zip">Release 5.3.3</a>
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index ae8dd1e66..30d76b1d3 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -888,12 +888,28 @@ TextSegment BreakFinder::Next() {
int charWidth = 1;
const char * const chars = &ll->chars[nextBreak];
const unsigned char ch = chars[0];
+ bool characterStyleConsistent = true; // All bytes of character in same style?
if (!UTF8IsAscii(ch) && encodingFamily != EncodingFamily::eightBit) {
if (encodingFamily == EncodingFamily::unicode) {
charWidth = UTF8DrawBytes(chars, lineRange.end - nextBreak);
} else {
charWidth = pdoc->DBCSDrawBytes(std::string_view(chars, lineRange.end - nextBreak));
}
+ for (int trail = 1; trail < charWidth; trail++) {
+ if (ll->styles[nextBreak] != ll->styles[nextBreak + trail]) {
+ characterStyleConsistent = false;
+ }
+ }
+ }
+ if (!characterStyleConsistent) {
+ if (nextBreak == prev) {
+ // Show first character representation bytes since it has inconsistent styles.
+ charWidth = 1;
+ } else {
+ // Return segment before nextBreak but allow to be split up if too long
+ // If not split up, next call will hit the above 'charWidth = 1;' and display bytes.
+ break;
+ }
}
repr = nullptr;
if (preprs->MayContain(ch)) {