forked from CodeEditApp/CodeEditSourceEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCEScrollView.swift
More file actions
28 lines (22 loc) · 783 Bytes
/
CEScrollView.swift
File metadata and controls
28 lines (22 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
}
}