aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation
diff options
context:
space:
mode:
Diffstat (limited to 'Map/Presentation')
-rw-r--r--Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift20
1 files changed, 20 insertions, 0 deletions
diff --git a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift
index c6ab483..a1b357d 100644
--- a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift
+++ b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift
@@ -96,8 +96,18 @@ class MapTextEditorController: NSViewController {
textView.textContainer?.widthTracksTextView = false
textView.textContainer?.containerSize = NSSize(
width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
+ // Allow text view to grow horizontally
+ textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
+ // Enable horizontal scrollbar when soft wrap is disabled
+ scrollView.hasHorizontalScroller = true
+ scrollView.horizontalScrollElasticity = .none
} else {
textView.textContainer?.widthTracksTextView = true
+ // Reset max size for wrapping
+ textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
+ // Hide horizontal scrollbar when soft wrap is enabled
+ scrollView.hasHorizontalScroller = false
+ scrollView.horizontalScrollElasticity = .automatic
}
textView.isHorizontallyResizable = true
@@ -169,6 +179,13 @@ class MapTextEditorController: NSViewController {
}
}
+ private func scrollToCursor() {
+ if let textView = currentTextView {
+ let cursorRange = textView.selectedRange()
+ textView.scrollRangeToVisible(cursorRange)
+ }
+ }
+
private func setupTrackingArea(for textView: NSTextView) {
let options: NSTrackingArea.Options = [.mouseEnteredAndExited, .mouseMoved, .activeInKeyWindow]
trackingArea = NSTrackingArea(
@@ -349,6 +366,9 @@ extension MapTextEditorController: NSTextViewDelegate {
if let textField = obj.object as? NSTextView {
self.text = textField.string
+ // Auto-scroll to keep cursor visible when typing
+ scrollToCursor()
+
changeDebouncer.debounce {
DispatchQueue.main.async {
self.onChange()