File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
Sources/CodeEditSourceEditor Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ class Highlighter: NSObject {
154154 /// - Parameter providers: All providers to use.
155155 public func setProviders( _ providers: [ HighlightProviding ] ) {
156156 guard let textView else { return }
157+ self . styleContainer. updateStorageLength ( newLength: textView. textStorage. length)
157158
158159 let existingIds : [ ObjectIdentifier ] = self . highlightProviders
159160 . compactMap { $0. highlightProvider }
Original file line number Diff line number Diff line change @@ -111,6 +111,25 @@ class StyledRangeContainer {
111111}
112112
113113extension StyledRangeContainer : HighlightProviderStateDelegate {
114+ func updateStorageLength( newLength: Int ) {
115+ for key in _storage. keys {
116+ guard var value = _storage [ key] else { continue }
117+ var store = value. store
118+ let length = store. length
119+ if length != newLength {
120+ let missingCharacters = newLength - length
121+ if missingCharacters < 0 {
122+ store. storageUpdated ( replacedCharactersIn: ( length + missingCharacters) ..< length, withCount: 0 )
123+ } else {
124+ store. storageUpdated ( replacedCharactersIn: length..< length, withCount: missingCharacters)
125+ }
126+ }
127+
128+ value. store = store
129+ _storage [ key] = value
130+ }
131+ }
132+
114133 /// Applies a highlight result from a highlight provider to the storage container.
115134 /// - Parameters:
116135 /// - provider: The provider sending the highlights.
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ struct RangeStore<Element: RangeStoreElement>: Sendable {
8484 /// - runs: The runs to insert.
8585 /// - range: The range to replace.
8686 mutating func set( runs: [ Run ] , for range: Range < Int > ) {
87- let gutsRange = 0 ..< _guts . count ( in : OffsetMetric ( ) )
87+ let gutsRange = 0 ..< length
8888 if range. clamped ( to: gutsRange) != range {
8989 let upperBound = range. clamped ( to: gutsRange) . upperBound
9090 let missingCharacters = range. upperBound - upperBound
You can’t perform that action at this time.
0 commit comments