@@ -136,6 +136,8 @@ extension TextView {
136136 setNeedsDisplay ( )
137137 }
138138
139+ // MARK: - Mouse Autoscroll
140+
139141 /// Sets up a timer that fires at a predetermined period to autoscroll the text view.
140142 /// Ensure the timer is disabled using ``disableMouseAutoscrollTimer``.
141143 func setUpMouseAutoscrollTimer( ) {
@@ -155,6 +157,8 @@ extension TextView {
155157 mouseDragTimer = nil
156158 }
157159
160+ // MARK: - Drag Selection
161+
158162 private func dragSelection( startPosition: Int , endPosition: Int , mouseDragAnchor: CGPoint ) {
159163 switch cursorSelectionMode {
160164 case . character:
@@ -196,41 +200,6 @@ extension TextView {
196200 private func dragColumnSelection( mouseDragAnchor: CGPoint , event: NSEvent ) {
197201 // Drag the selection and select in columns
198202 let eventLocation = convert ( event. locationInWindow, from: nil )
199-
200- let start = CGPoint (
201- x: min ( mouseDragAnchor. x, eventLocation. x) ,
202- y: min ( mouseDragAnchor. y, eventLocation. y)
203- )
204- let end = CGPoint (
205- x: max ( mouseDragAnchor. x, eventLocation. x) ,
206- y: max ( mouseDragAnchor. y, eventLocation. y)
207- )
208-
209- // Collect all overlapping text ranges
210- var selectedRanges : [ NSRange ] = layoutManager. linesStartingAt ( start. y, until: end. y) . flatMap { textLine in
211- // Collect fragment ranges
212- return textLine. data. lineFragments. compactMap { lineFragment -> NSRange ? in
213- let startOffset = self . layoutManager. textOffsetAtPoint (
214- start,
215- fragmentPosition: lineFragment,
216- linePosition: textLine
217- )
218- let endOffset = self . layoutManager. textOffsetAtPoint (
219- end,
220- fragmentPosition: lineFragment,
221- linePosition: textLine
222- )
223- guard let startOffset, let endOffset else { return nil }
224-
225- return NSRange ( start: startOffset, end: endOffset)
226- }
227- }
228-
229- // If we have some non-cursor selections, filter out any cursor selections
230- if selectedRanges. contains ( where: { !$0. isEmpty } ) {
231- selectedRanges = selectedRanges. filter ( { !$0. isEmpty } )
232- }
233-
234- selectionManager. setSelectedRanges ( selectedRanges)
203+ selectColumns ( betweenPointA: eventLocation, pointB: mouseDragAnchor)
235204 }
236205}
0 commit comments