diff options
author | Neil <nyamatongwe@gmail.com> | 2023-02-13 14:02:40 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2023-02-13 14:02:40 +1100 |
commit | 7179a3d6db03425155b56141a15b76e80fd30efa (patch) | |
tree | a0535ab6040aa9a4497df6907178d020d31528c3 /src | |
parent | 80a1e22a987c4e749dd03500edc3ac4e189537c5 (diff) | |
download | scintilla-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.
Diffstat (limited to 'src')
-rw-r--r-- | src/PositionCache.cxx | 16 |
1 files changed, 16 insertions, 0 deletions
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)) { |