NSTextView.shouldDrawInsertionPoint doesn't work with TextKit 2

The following code only ever causes shouldDrawInsertionPoint to be printed (no drawInsertionPoint), but even if that method returns false, the blinking insertion point is still drawn. On the other hand, with TextKit 1 it works as expected.

Is there a way to hide the default insertion point in TextKit 2? My app draws its own.

I've filed FB13684251.

class TextView: NSTextView {
    
    override var shouldDrawInsertionPoint: Bool {
        print("shouldDrawInsertionPoint")
        return false
    }
    
    override func drawInsertionPoint(in rect: NSRect, color: NSColor, turnedOn flag: Bool) {
        print("drawInsertionPoint", flag)
    }
    
}
``
Answered by DTS Engineer in 833261022

Hi and thanks for filing a bug report. I checked the status today and there's a note asking you to test with the most recent beta. To avoid your bug report being closed, please do some testing and update your bug when you have a chance.

Please continue to test your software in release and pre-release versions of system software made available to you through your developer.apple.com account. When you do, add details about that into your bug report to keep it up to date. Please see https://developer.apple.com/download/.

Hi and thanks for filing a bug report. I checked the status today and there's a note asking you to test with the most recent beta. To avoid your bug report being closed, please do some testing and update your bug when you have a chance.

Please continue to test your software in release and pre-release versions of system software made available to you through your developer.apple.com account. When you do, add details about that into your bug report to keep it up to date. Please see https://developer.apple.com/download/.

Sorry, I copied the wrong number. That one had the same title but was actually addressing TextKit 1. The correct number is FB17103305.

No problem. Thanks for the update. I checked in your FB17103305 report and it is up to date and has been routed to the correct engineering team. No news yet. Your Feedback report remains open and under investigation. I'll check back again later.

What is the status of this issue?

I do not think I am using TextKit 2. I install my own layout manager, and it's my understanding that that disables TextKit 2.

Nevertheless, overriding shouldDrawInsertionPoint so that it returns false does not consistently disable insertion-point drawing in my custom NSTextView.

My custom NSTextView used to work: the default insertion point was never shown. That was precisely what I expected and needed.

BTW, if I add a Swift.print statement to my shouldDrawInsertionPoint override, I see that my override is evaluated whenever my selectedRanges willSet handler is called. However, when my setSelectedRanges override (which calls the super implementation, always) is called, shouldDrawInsertionPoint usually is not evaluated.

I am using macOS Sonoma, BTW.

I do not think I am using TextKit 2. I install my own layout manager, and it's my understanding that that disables TextKit 2.

Could you share some code?

I was mistaken, I do not use my own layout manager. I do, however, install my own NSLayoutManagerDelegate and NSTextStorage. IIUC, that also opts a program out of TextKit 2:


class ViewController: NSViewController, NSTextViewDelegate,
    NSLayoutManagerDelegate {
        typealias Storage = ExpandedRopeTextStorage
*snip snip*
        override public func viewWillAppear() {
                textView.layoutManager!.allowsNonContiguousLayout = true
                textView.layoutManager!.replaceTextStorage(storage)
                if textView.textStorage is Storage {
                        Swift.print("storage properly replaced")
                }
                textView.wantsLayer = true
                textView.layoutManager!.delegate = self
*snip snip*

BTW, I just tried my program on macOS Ventura. My custom cursor replaces the AppKit default cursor in every instance on Ventura. Looks like AppKit may have broken between Ventura and Sonoma.

My custom cursor replaces the AppKit default cursor in every instance on Ventura.

Previously you said that it didn't work consistently. So does it work now? Since you're using TextKit 1 (by explicitly accessing layoutManager), that's expected: I managed to make it work with TextKit 1 as well, but was asking about TextKit 2, where it doesn't work.

No, it does not work on Sonoma. Sonoma does not always honor shouldDrawInsertionPoint. Ventura, however, consistently respects my shouldDrawInsertionPoint override.

Ah, I confused the macOS names. Can you show the code with your override and custom drawing?

NSTextView.shouldDrawInsertionPoint doesn't work with TextKit 2
 
 
Q