0

I’m attempting to update a Cocoa app for the first time in perhaps 8 years. It seems to build OK, and mostly runs fine too. I can edit text, but the insertion point doesn’t blink.

I use an NSTextView subclass to display text. I’m rusty at Cocoa, so I am guessing something changed with app napping or the like. Is there anything I need to do to make sure insertion points blink? More likely, what did I break to prevent periodic updating in the modern battery-friendly way?

David Dunham
  • 8,139
  • 3
  • 28
  • 41

2 Answers2

0

I have the same problem with NSTextView and after multiples tests, it seems that bug happens with every basic textView on macOS 10.14 for me.

I've searched for multiple fixes on the web with no result. The best workaround I've found is to set the textView delegate to itself. Then, on didProcessEditing, call updateInsertionPointStateAndRestartTimer on the main thread as the following :

class CustomTextView: NSTextView {

    override func awakeFromNib() {
        super.awakeFromNib()

        // 1. Set the textStorage delegate
        textStorage?.delegate = self
    }

}

extension CustomTextView: NSTextStorageDelegate {

    func textStorage(_ textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int) {
        // 2. On the main thread, update the insertion point
        DispatchQueue.main.async {
            self.updateInsertionPointStateAndRestartTimer(true)
    }

}
bpisano
  • 335
  • 3
  • 13
  • We seem to have the same problem. Did you solve it in the end? Please help me see this: https://stackoverflow.com/questions/57523797/nstextviews-insertion-point-draws-position-exceptions – Simon Aug 16 '19 at 11:40
-1

OK, just in case this bites someone else: I had switched to dark mode. Apparently the default insertion point is white, so I couldn’t see it flash against the white background. So I need to properly support dark mode.

David Dunham
  • 8,139
  • 3
  • 28
  • 41
  • That sure seems like a bug on Apple's part… Shouldn't they change it automatically when you go into dark mode? Or did you set the cursor manually? – Dad Nov 03 '18 at 17:16
  • No, it’s not manual. (I think I saw the same thing with Terminal.app …) – David Dunham Nov 03 '18 at 21:02