Compare commits

...

2 Commits

2 changed files with 13 additions and 4 deletions

View File

@ -225,8 +225,6 @@ class JavaScriptHighlighter {
consumeDotLookup() consumeDotLookup()
} else if char == "?" { } else if char == "?" {
consumeTernaryExpression() consumeTernaryExpression()
} else if expressionEnds.contains(char) {
return
} else { } else {
consume() consume()
} }

View File

@ -7,6 +7,7 @@
// //
import AppKit import AppKit
import Combine
class JavaScriptEditorView: NSTextView { class JavaScriptEditorView: NSTextView {
@ -24,6 +25,9 @@ class JavaScriptEditorView: NSTextView {
} }
} }
private let rehighlightSubject = PassthroughSubject<Void, Never>()
private var debouncedRehighlightCancellable: AnyCancellable!
func rehighlight() { func rehighlight() {
isRehighlighting = true isRehighlighting = true
highlighter.highlight(attributed: self.textStorage!) highlighter.highlight(attributed: self.textStorage!)
@ -34,6 +38,13 @@ class JavaScriptEditorView: NSTextView {
super.awakeFromNib() super.awakeFromNib()
textStorage!.delegate = self textStorage!.delegate = self
typingAttributes = [
.font: NSFont.monospacedSystemFont(ofSize: 13, weight: .regular),
.foregroundColor: NSColor.textColor
]
debouncedRehighlightCancellable = rehighlightSubject.throttle(for: .milliseconds(40), scheduler: RunLoop.main, latest: false).sink(receiveValue: rehighlight)
} }
override func shouldChangeText(in affectedCharRange: NSRange, replacementString: String?) -> Bool { override func shouldChangeText(in affectedCharRange: NSRange, replacementString: String?) -> Bool {
@ -117,6 +128,6 @@ extension JavaScriptEditorView: NSTextStorageDelegate {
} }
} }
rehighlight() rehighlightSubject.send()
} }
} }