@@ -19,50 +19,6 @@ public protocol TextSelectionManagerDelegate: AnyObject {
19
19
/// Draws selections using a draw method similar to the `TextLayoutManager` class, and adds cursor views when
20
20
/// appropriate.
21
21
public class TextSelectionManager : NSObject {
22
- // MARK: - TextSelection
23
-
24
- public class TextSelection : Hashable , Equatable {
25
- public var range : NSRange
26
- weak var view : NSView ?
27
- var boundingRect : CGRect = . zero
28
- var suggestedXPos : CGFloat ?
29
- /// The position this selection should 'rotate' around when modifying selections.
30
- var pivot : Int ?
31
-
32
- init ( range: NSRange , view: CursorView ? = nil ) {
33
- self . range = range
34
- self . view = view
35
- }
36
-
37
- var isCursor : Bool {
38
- range. length == 0
39
- }
40
-
41
- public func hash( into hasher: inout Hasher ) {
42
- hasher. combine ( range)
43
- }
44
-
45
- public static func == ( lhs: TextSelection , rhs: TextSelection ) -> Bool {
46
- lhs. range == rhs. range
47
- }
48
- }
49
-
50
- public enum Destination {
51
- case character
52
- case word
53
- case line
54
- case visualLine
55
- case page
56
- case document
57
- }
58
-
59
- public enum Direction {
60
- case up
61
- case down
62
- case forward
63
- case backward
64
- }
65
-
66
22
// MARK: - Properties
67
23
68
24
// swiftlint:disable:next line_length
@@ -108,6 +64,8 @@ public class TextSelectionManager: NSObject {
108
64
109
65
// MARK: - Selected Ranges
110
66
67
+ /// Set the selected ranges to a single range. Overrides any existing selections.
68
+ /// - Parameter range: The range to set.
111
69
public func setSelectedRange( _ range: NSRange ) {
112
70
textSelections. forEach { $0. view? . removeFromSuperview ( ) }
113
71
let selection = TextSelection ( range: range)
@@ -119,6 +77,8 @@ public class TextSelectionManager: NSObject {
119
77
}
120
78
}
121
79
80
+ /// Set the selected ranges to new ranges. Overrides any existing selections.
81
+ /// - Parameter range: The selected ranges to set.
122
82
public func setSelectedRanges( _ ranges: [ NSRange ] ) {
123
83
textSelections. forEach { $0. view? . removeFromSuperview ( ) }
124
84
// Remove duplicates, invalid ranges, update suggested X position.
@@ -138,6 +98,8 @@ public class TextSelectionManager: NSObject {
138
98
}
139
99
}
140
100
101
+ /// Append a new selected range to the existing ones.
102
+ /// - Parameter range: The new range to add.
141
103
public func addSelectedRange( _ range: NSRange ) {
142
104
let newTextSelection = TextSelection ( range: range)
143
105
var didHandle = false
@@ -336,14 +298,3 @@ public class TextSelectionManager: NSObject {
336
298
context. restoreGState ( )
337
299
}
338
300
}
339
-
340
- // MARK: - Private TextSelection
341
-
342
- private extension TextSelectionManager . TextSelection {
343
- func didInsertText( length: Int , retainLength: Bool = false ) {
344
- if !retainLength {
345
- range. length = 0
346
- }
347
- range. location += length
348
- }
349
- }
0 commit comments