Skip to content

Commit 7c8cb37

Browse files
committed
fix: prevent crash from stale emphasis range during text edits
- Clear emphasis immediately on text change (before debounced update) to avoid drawing a stale range that extends beyond the document - Validate NSMaxRange(stmtRange) <= docLength before adding emphasis
1 parent 477b6bf commit 7c8cb37

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

TablePro/Views/Editor/CurrentStatementHighlighter.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ final class CurrentStatementHighlighter {
3636
}
3737

3838
func handleTextChange() {
39-
// Text changed — invalidate cached range and schedule update
40-
lastHighlightedRange = nil
39+
// Clear emphasis immediately so stale ranges don't cause drawing crashes.
40+
// The debounced update will re-apply with the correct range.
41+
clearHighlight()
4142
scheduleUpdate()
4243
}
4344

@@ -92,7 +93,8 @@ final class CurrentStatementHighlighter {
9293
let stmtNS = located.sql as NSString
9394
let stmtRange = NSRange(location: located.offset, length: stmtNS.length)
9495

95-
guard stmtRange.length > 0 else {
96+
// Validate range is within document bounds
97+
guard stmtRange.length > 0, NSMaxRange(stmtRange) <= docLength else {
9698
clearHighlight()
9799
return
98100
}

0 commit comments

Comments
 (0)