Skip to content

Commit 1beac47

Browse files
Fix StyledRangeStore Crash (#303)
### Description Fixes a potential crash with the styled range store. This is caused by a race condition where the store hasn't been notified of a content length change, but has been given new data to put in the (valid) range. This only happens when content is appended to the end of a document and comes into view at the same time. This is fixed by simply appending the missing range when updating the style storage object. ### Related Issues N/A ### Checklist <!--- Add things that are not yet implemented above --> - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots N/A
1 parent f444927 commit 1beac47

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeStore/StyledRangeStore.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ final class StyledRangeStore {
7373
/// - runs: The runs to insert.
7474
/// - range: The range to replace.
7575
func set(runs: [Run], for range: Range<Int>) {
76+
let gutsRange = 0..<_guts.count(in: OffsetMetric())
77+
if range.clamped(to: gutsRange) != range {
78+
let upperBound = range.clamped(to: gutsRange).upperBound
79+
let missingCharacters = range.upperBound - upperBound
80+
storageUpdated(replacedCharactersIn: upperBound..<upperBound, withCount: missingCharacters)
81+
}
82+
7683
_guts.replaceSubrange(
7784
range,
7885
in: OffsetMetric(),

0 commit comments

Comments
 (0)