I am working on an NSTextView subclass and now need to draw text insertion points by myself during the formal NSTextView's insertion point timer stops. I succeed to draw my own, but could not find the way to obtain the time interval for the text insertion point blinking.
According to my observation on NSTextView, an NSTextView (subclass) manages the cursor blink using a private NSTimer, but this timer deactivates when the textView has only nonempty selections (because there is no insertion point to draw) or while dragging. Therefore, I need to have my own timer with a proper interval to draw my fake insertion points.
Digging the source code of the ancient OpenStep, the magic number for it seems to be 0.5 seconds. However, nowadays, users can customize the interval or even disable blinking. Likewise, the system also may change the interval for specific situations or in the future. I'd like to respect those preferences but I could not find the proper way for it.
Does anyone know how to get it (without accessing private API)?
What I do so far is:
private struct BlinkPeriod {
var on: Int
var off: Int
}
private extension UserDefaults {
var textInsertionPointBlinkPeriod: BlinkPeriod {
let onPeriod = self.integer(forKey: "NSTextInsertionPointBlinkPeriodOn")
let offPeriod = self.integer(forKey: "NSTextInsertionPointBlinkPeriodOff")
return BlinkPeriod(on: (onPeriod > 0) ? onPeriod : 500,
off: (offPeriod > 0) ? offPeriod : 500)
}
}
But I feel it's dirty and no idea when the system changed the period :/