Skip to content

Commit 39db327

Browse files
Update Visible Set When Invalidated (#192)
<!--- IMPORTANT: If this PR addresses multiple unrelated issues, it will be closed until separated. --> ### Description Adds a method to update the visible set and adds a call to that method when invalidating the entire document to ensure any newly visible text is correctly re-highlighted. ### Related Issues - Closes #190 ### 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 https://github.com/CodeEditApp/CodeEditTextView/assets/35942988/05347932-ed0b-4a72-ace4-551300e5e7aa
1 parent 2a39fd0 commit 39db327

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Sources/CodeEditTextView/Highlighting/Highlighter.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class Highlighter: NSObject {
107107

108108
/// Invalidates all text in the textview. Useful for updating themes.
109109
public func invalidate() {
110+
updateVisibleSet()
110111
invalidate(range: NSRange(entireTextRange))
111112
}
112113

@@ -245,11 +246,15 @@ private extension Highlighter {
245246
// MARK: - Visible Content Updates
246247

247248
private extension Highlighter {
248-
/// Updates the view to highlight newly visible text when the textview is scrolled or bounds change.
249-
@objc func visibleTextChanged(_ notification: Notification) {
249+
private func updateVisibleSet() {
250250
if let newVisibleRange = textView.visibleTextRange {
251251
visibleSet = IndexSet(integersIn: newVisibleRange)
252252
}
253+
}
254+
255+
/// Updates the view to highlight newly visible text when the textview is scrolled or bounds change.
256+
@objc func visibleTextChanged(_ notification: Notification) {
257+
updateVisibleSet()
253258

254259
// Any indices that are both *not* valid and in the visible text range should be invalidated
255260
let newlyInvalidSet = visibleSet.subtracting(validSet)

0 commit comments

Comments
 (0)