Skip to content

Commit 93c5404

Browse files
committed
Fix a crash that calls dropLast with a negative number
1 parent 1cf2781 commit 93c5404

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Tool/Sources/SuggestionModel/EditorInformation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ public struct EditorInformation {
102102
}
103103
var content = rangeLines
104104
if !content.isEmpty {
105+
let dropLastCount = max(0, content[content.endIndex - 1].count - range.end.character)
105106
content[content.endIndex - 1] = String(
106-
content[content.endIndex - 1].dropLast(
107-
content[content.endIndex - 1].count - range.end.character
108-
)
107+
content[content.endIndex - 1].dropLast(dropLastCount)
109108
)
110-
content[0] = String(content[0].dropFirst(range.start.character))
109+
let dropFirstCount = max(0, range.start.character)
110+
content[0] = String(content[0].dropFirst(dropFirstCount))
111111
}
112112
return (content.joined(), rangeLines)
113113
}

0 commit comments

Comments
 (0)