diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-08-01 15:40:56 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-08-01 15:40:56 +0200 |
| commit | c2b185fa47f43d866b902beeee30da38a2017503 (patch) | |
| tree | fe6b87b8508dc9e5f480498138686dcf5c65a794 /Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift | |
| parent | 143f2bbb517c9f25b99d00a16d9850dbdbd09ae1 (diff) | |
Fix incorrect scroll bounds when soft wrap is disabled
Diffstat (limited to 'Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift')
| -rw-r--r-- | Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift | 20 |
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() |