diff --git a/Sources/CodeEditSourceEditor/Highlighting/HighlighProviding/HighlightProviderState.swift b/Sources/CodeEditSourceEditor/Highlighting/HighlighProviding/HighlightProviderState.swift index 6fca2123b..8b42ba229 100644 --- a/Sources/CodeEditSourceEditor/Highlighting/HighlighProviding/HighlightProviderState.swift +++ b/Sources/CodeEditSourceEditor/Highlighting/HighlighProviding/HighlightProviderState.swift @@ -139,8 +139,9 @@ extension HighlightProviderState { highlightProvider?.applyEdit(textView: textView, range: range, delta: delta) { [weak self] result in switch result { case .success(let invalidSet): + let modifiedRange = NSRange(location: range.location, length: range.length + delta) // Make sure we add in the edited range too - self?.invalidate(invalidSet.union(IndexSet(integersIn: range))) + self?.invalidate(invalidSet.union(IndexSet(integersIn: modifiedRange))) case .failure(let error): if case HighlightProvidingError.operationCancelled = error { self?.invalidate(IndexSet(integersIn: range)) diff --git a/Tests/CodeEditSourceEditorTests/Highlighting/HighlightProviderStateTest.swift b/Tests/CodeEditSourceEditorTests/Highlighting/HighlightProviderStateTest.swift index d3f89f0cc..e730e16de 100644 --- a/Tests/CodeEditSourceEditorTests/Highlighting/HighlightProviderStateTest.swift +++ b/Tests/CodeEditSourceEditorTests/Highlighting/HighlightProviderStateTest.swift @@ -116,12 +116,13 @@ final class HighlightProviderStateTest: XCTestCase { language: .swift ) + // These reflect values like `NSTextStorage` outputs, and differ from ranges used in other tests. let mockEdits: [(NSRange, Int)] = [ - (NSRange(location: 0, length: 10), 10), // Inserted 10 - (NSRange(location: 5, length: 0), -2), // Deleted 2 at 5 - (NSRange(location: 0, length: 2), 3), // Replaced 0-2 with 3 + (NSRange(location: 0, length: 0), 10), // Inserted 10 + (NSRange(location: 3, length: 2), -2), // Deleted 2 at 5 + (NSRange(location: 0, length: 2), 1), // Replaced 0-2 with 3 (NSRange(location: 9, length: 1), 1), - (NSRange(location: 0, length: 0), -10) + (NSRange(location: 0, length: 10), -10) ] for edit in mockEdits {