Skip to content

Commit f8433f3

Browse files
committed
Sanity Check Range
1 parent 2f1fdad commit f8433f3

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

Sources/CodeEditSourceEditor/LineFolding/Model/LineFoldCalculator.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class LineFoldCalculator {
101101
var results: [(index: Int, foldDepth: Int)] = []
102102
var count = 0
103103
while count < 50, let linePosition = iterator.next() {
104-
guard let substring = textView.textStorage.substring(from: linePosition.range) as NSString?,
104+
guard textView.textStorage.length <= linePosition.range.max,
105+
let substring = textView.textStorage.substring(from: linePosition.range) as NSString?,
105106
let foldDepth = foldProvider.foldLevelAtLine(
106107
linePosition.index,
107108
substring: substring

0 commit comments

Comments
 (0)