Is multiple insertion points possible in NSTextView?
13:57 16 Apr 2026

I'm trying to modify how NSTextView behaves with multiple selections. More precisely I'd like to override moveLeft: so that it doesn't collapse the selection to the first location, but rather the first location of each selection.

Naively I experimented with the following code:

@objc override func moveLeft(_ sender: Any?) {
    if selectedRanges.count < 2 {
        super.moveLeft(sender)
        return
    }
    let ranges = selectedRanges.map { NSValue(range: NSMakeRange($0.rangeValue.location, 0)) }
    setSelectedRanges(ranges, affinity: .downstream, stillSelecting: false)
}

But, alas, somewhere else something applies the default behaviour on the selection after my changes. E.g.

[NSRange: {95, 1}, NSRange: {105, 1}, NSRange: {115, 1}, NSRange: {125, 1}]

after moveLeft:

[NSRange: {95, 0}, NSRange: {105, 0}, NSRange: {115, 0}, NSRange: {125, 0}]

ends up as

[NSRange: {95, 0}]

Is a range with length zero only valid for single selection?

Is there some way to achieve what I want (short of implementing my own text system)?

nstextview textselection