Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate Correct Edited Range #279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading