aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-07-14 15:50:09 +1000
committerNeil <nyamatongwe@gmail.com>2021-07-14 15:50:09 +1000
commit0a5f16edd287fba222214b89661285191e7af898 (patch)
treebaed7e9e2f14fbe94b046bfd382f1782e60d98c3 /src
parent289314060dd7a44f9844cfc891d1c1d823742f94 (diff)
downloadscintilla-mirror-0a5f16edd287fba222214b89661285191e7af898.tar.gz
Feature [feature-requests:#1408] More accurate handling of invalid DBCS byte
pairs in backwards NextPosition.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 6dc14238f..e0fd78eda 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -838,8 +838,13 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const noexc
if ((pos - 1) <= posStartLine) {
return pos - 1;
} else if (IsDBCSLeadByteNoExcept(cb.CharAt(pos - 1))) {
- // Must actually be trail byte
- return pos - 2;
+ // Should actually be trail byte
+ if (IsDBCSDualByteAt(pos - 2)) {
+ return pos - 2;
+ } else {
+ // Invalid byte pair so treat as one byte wide
+ return pos - 1;
+ }
} else {
// Otherwise, step back until a non-lead-byte is found.
Sci::Position posTemp = pos - 1;
@@ -848,7 +853,12 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const noexc
// Now posTemp+1 must point to the beginning of a character,
// so figure out whether we went back an even or an odd
// number of bytes and go back 1 or 2 bytes, respectively.
- return (pos - 1 - ((pos - posTemp) & 1));
+ const Sci::Position widthLast = ((pos - posTemp) & 1) + 1;
+ if ((widthLast == 2) && (IsDBCSDualByteAt(pos - widthLast))) {
+ return pos - widthLast;
+ }
+ // Byte before pos may be valid character or may be an invalid second byte
+ return pos - 1;
}
}
}