Skip to content

Commit

Permalink
remove implicit re-validation on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Feb 1, 2024
1 parent 8483025 commit 64c168b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Sources/Neon/TextViewHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public final class TextViewHighlighter: NSObject {
extension TextViewHighlighter: NSTextStorageDelegate {
public nonisolated func textStorage(_ textStorage: NSTextStorage, willProcessEditing editedMask: TextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int) {
MainActor.backport.assumeIsolated {
// a change happening, start buffering invalidations
buffer.beginBuffering()

client.willChangeContent(in: editedRange)
}
}
Expand All @@ -146,8 +149,13 @@ extension TextViewHighlighter: NSTextStorageDelegate {

let adjustedRange = NSRange(location: editedRange.location, length: editedRange.length - delta)

styler.didChangeContent(in: adjustedRange, delta: delta)
client.didChangeContent(in: adjustedRange, delta: delta)
styler.didChangeContent(in: adjustedRange, delta: delta)

// At this point in mutation processing, it is unsafe to apply style changes. Ideally, we'd have a hook so we can know when it is ok. But, no such system exists for stock TextKit 1/2. So, instead we just let the runloop turn. This is *probably* safe, if the text does not change again, but can also result in flicker.
DispatchQueue.main.backport.asyncUnsafe {
self.buffer.endBuffering()
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/RangeState/RangeValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ public final class RangeValidator<Content: VersionedContent> {

// if we have pending requests, we have to start over
self.pendingSet.removeAll()

makeNextWorkingSetRequest()
}
}

Expand Down

0 comments on commit 64c168b

Please sign in to comment.