aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZufu Liu <unknown>2025-06-17 13:25:27 +1000
committerZufu Liu <unknown>2025-06-17 13:25:27 +1000
commitc654993b564b128b01cd57fbe6bf1a5aa753ee47 (patch)
tree5d24f91744b0b020bfd4499c2f6b03bc05606134
parentb1dcfa8dc328644f2a68c5168130b9e66a842427 (diff)
downloadscintilla-mirror-c654993b564b128b01cd57fbe6bf1a5aa753ee47.tar.gz
Feature [feature-requests:#1557]. Fix finding sub-line of position in
bidirectional mode which is used for accessibility on macOS with VoiceOver. Avoid out-of-bounds access.
-rw-r--r--src/PositionCache.cxx18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index d0fb6acf7..16bc10f5a 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -167,22 +167,20 @@ bool LineLayout::InLine(int offset, int line) const noexcept {
}
int LineLayout::SubLineFromPosition(int posInLine, PointEnd pe) const noexcept {
- if (!lineStarts || (posInLine > maxLineLength)) {
+ if (lines <= 1 || (posInLine >= numCharsBeforeEOL)) {
return lines - 1;
}
- for (int line = 0; line < lines; line++) {
- if (FlagSet(pe, PointEnd::subLineEnd)) {
- // Return subline not start of next
- if (lineStarts[line + 1] <= posInLine + 1)
- return line;
- } else {
- if (lineStarts[line + 1] <= posInLine)
- return line;
+ // Return subline not start of next for PointEnd::subLineEnd
+ posInLine -= FlagSet(pe, PointEnd::subLineEnd) ? 1 : 0;
+ int line = 1;
+ for (; line < lines; line++) {
+ if (lineStarts[line] > posInLine) {
+ break;
}
}
- return lines - 1;
+ return line - 1;
}
void LineLayout::AddLineStart(Sci::Position start) {