Skip to content

Commit

Permalink
Reload editor (#122)
Browse files Browse the repository at this point in the history
## What is it?
Addresses bug:
https://github.com/CodeEditApp/CodeEditTextView/issues/110, and maybe
others- but I need to hunt them down.

Ensures that highlights aren't lost when processing these updates.

## UI Behavior


https://user-images.githubusercontent.com/5067237/213246192-9c27e0ae-9024-4f73-b721-db0bb1fc3251.mp4
  • Loading branch information
lukepistrol authored Jan 18, 2023
2 parents 86940ec + 5e654be commit 9f79fa8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/CodeEditTextView/STTextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt

/// Reloads the UI to apply changes to ``STTextViewController/font``, ``STTextViewController/theme``, ...
internal func reloadUI() {
textView?.font = font
// if font or baseline has been modified, set the hasSetStandardAttributesFlag
// to false to ensure attributes are updated. This allows live UI updates when changing preferences.
if textView?.font != font || rulerView.baselineOffset != baselineOffset {
hasSetStandardAttributes = false
}

textView?.textColor = theme.text
textView?.backgroundColor = theme.background
textView?.insertionPointColor = theme.insertionPoint
Expand All @@ -223,6 +228,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
guard !hasSetStandardAttributes else { return }
hasSetStandardAttributes = true
textView.addAttributes(attributesFor(nil), range: .init(0..<textView.string.count))
highlighter?.invalidate()
}

/// Gets all attributes for the given capture including the line height, background color, and text color.
Expand Down

0 comments on commit 9f79fa8

Please sign in to comment.