Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Sources/CodeEditTextView/CEScrollView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// CEScrollView.swift
//
//
// Created by Renan Greca on 18/02/23.
//

import AppKit
import STTextView

class CEScrollView: NSScrollView {

override func mouseDown(with event: NSEvent) {

if let textView = self.documentView as? STTextView,
!textView.visibleRect.contains(event.locationInWindow) {
// If the `scrollView` was clicked, but the click did not happen within the `textView`,
// set cursor to the last index of the `textView`.

let endLocation = textView.textLayoutManager.documentRange.endLocation
let range = NSTextRange(location: endLocation)
_ = textView.becomeFirstResponder()
textView.setSelectedRange(range)
}

super.mouseDown(with: event)
}
}
2 changes: 1 addition & 1 deletion Sources/CodeEditTextView/STTextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
public override func loadView() {
textView = STTextView()

let scrollView = NSScrollView()
let scrollView = CEScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.hasVerticalScroller = true
scrollView.documentView = textView
Expand Down