aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Base Components/MapTextEditor.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-09-16 20:56:23 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2024-09-16 20:56:23 +0200
commited10ac191df473c92c4fec495aafa7f569d108c8 (patch)
tree5655074ca26c51fe001df91859649aa6599993d5 /Map/Presentation/Base Components/MapTextEditor.swift
parent9703ef690a21067a1929f3020350e0d5d459f8ef (diff)
Add some debouncing
Diffstat (limited to 'Map/Presentation/Base Components/MapTextEditor.swift')
-rw-r--r--Map/Presentation/Base Components/MapTextEditor.swift18
1 files changed, 6 insertions, 12 deletions
diff --git a/Map/Presentation/Base Components/MapTextEditor.swift b/Map/Presentation/Base Components/MapTextEditor.swift
index 2e4f279..ff98203 100644
--- a/Map/Presentation/Base Components/MapTextEditor.swift
+++ b/Map/Presentation/Base Components/MapTextEditor.swift
@@ -89,10 +89,11 @@ class MapTextEditorController: NSViewController {
textStorage.removeAttribute(
.backgroundColor, range: NSRange(location: 0, length: textStorage.length))
- for range in highlightRanges {
+ for (index, range) in highlightRanges.enumerated() {
let nsRange = NSRange(range, in: textStorage.string)
- textStorage.addAttribute(.backgroundColor, value: NSColor.Syntax.match, range: nsRange)
+ let color = index == selectedRange ? NSColor.Syntax.highlightMatch : NSColor.Syntax.match
+ textStorage.addAttribute(.backgroundColor, value: color, range: nsRange)
}
textView.needsDisplay = true
@@ -108,19 +109,10 @@ class MapTextEditorController: NSViewController {
let range = highlightRanges[selectedRange]
let nsRange = NSRange(range, in: textStorage.string)
textView.scrollRangeToVisible(nsRange)
- textView.selectedRange = nsRange
}
}
}
}
-
- private func setSelectionColor() {
- guard let textView = self.textView else { return }
-
- var selectedTextAttributes = textView.selectedTextAttributes
- selectedTextAttributes[.backgroundColor] = NSColor.yellow.withAlphaComponent(0.3)
- textView.selectedTextAttributes = selectedTextAttributes
- }
}
extension MapTextEditorController: NSTextViewDelegate {
@@ -259,6 +251,8 @@ struct MapTextEditor: NSViewControllerRepresentable {
context: NSViewControllerRepresentableContext<MapTextEditor>
) {
nsViewController.highlightRanges = highlightRanges
- nsViewController.selectedRange = selectedRange
+ if nsViewController.selectedRange != selectedRange {
+ nsViewController.selectedRange = selectedRange
+ }
}
}