Skip to content

Commit

Permalink
Fix confused cursor positioning in clipRTLLines
Browse files Browse the repository at this point in the history
FIX: Fix an infinite loop that could occur when enabling `bidiIsolates` in documents with
both bidirectional text and very long lines.

See https://issues.chromium.org/issues/342778297
  • Loading branch information
marijnh committed Jun 3, 2024
1 parent 3c9ad8f commit cb00e70
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ function buildDeco(view: EditorView, tree: Tree, always: boolean) {
function clipRTLLines(ranges: readonly {from: number, to: number}[], doc: Text) {
let cur = doc.iter(), pos = 0, result: {from: number, to: number}[] = [], last = null
for (let {from, to} of ranges) {
if (from != pos) {
if (pos < from) cur.next(from - pos)
if (last && last.to > from) {
from = last.to
if (from >= to) continue
}
if (pos + cur.value.length < from) {
cur.next(from - (pos + cur.value.length))
pos = from
}
for (;;) {
Expand All @@ -109,7 +113,7 @@ function clipRTLLines(ranges: readonly {from: number, to: number}[], doc: Text)
if (last && last.to > start - 10) last.to = Math.min(to, end)
else result.push(last = {from: start, to: Math.min(to, end)})
}
if (pos >= to) break
if (end >= to) break
pos = end
cur.next()
}
Expand Down

0 comments on commit cb00e70

Please sign in to comment.