Skip to content

Commit

Permalink
Add own insertion indicator while rectangular selection
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 16, 2023
1 parent 2abd792 commit d3594cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CotEditor/Sources/EditorTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, MultiCursor

self.mouseDownPoint = self.convert(event.locationInWindow, from: nil)
self.isPerformingRectangularSelection = event.modifierFlags.contains(.option)
self.needsUpdateInsertionIndicators = true // to draw dummy indicator for proper one while selecting
self.updateInsertionPointTimer()

let selectedRange = self.selectedRange.isEmpty ? self.selectedRange : nil
Expand Down
5 changes: 4 additions & 1 deletion CotEditor/Sources/NSTextView+MultiCursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,14 @@ extension MultiCursorEditing {

guard !self.insertionLocations.isEmpty || !self.insertionIndicators.isEmpty else { return }

let properInsertionLocations = (self.isPerformingRectangularSelection && self.selectedRange.isEmpty) ? [self.selectedRange.location] : []
let insertionLocations = (self.insertionLocations + properInsertionLocations)

// reuse existing indicators
var indicators = ArraySlice(self.insertionIndicators) // slice for popFirst()
let isActive = (self.window?.firstResponder == self && NSApp.isActive)

self.insertionIndicators = self.insertionLocations
self.insertionIndicators = insertionLocations
.compactMap { self.insertionPointRects(at: $0).first } // ignore split cursors
.map { rect in
if let indicator = indicators.popFirst() {
Expand Down

0 comments on commit d3594cb

Please sign in to comment.