NSTextView插入点不闪烁

时间:2018-10-21 00:19:41

标签: cocoa

我可能是8年以来第一次尝试更新Cocoa应用。它似乎可以正常运行,并且也可以正常运行。我可以编辑文本,但是插入点没有闪烁。

我使用NSTextView子类来显示文本。我对Cocoa感到生疏,所以我猜是因为应用小睡或类似情况有所改变。我需要做些什么来确保插入点闪烁吗?为了防止以现代的电池友好方式进行定期更新,我有什么可能要做的事情?

2 个答案:

答案 0 :(得分:0)

我在使用NSTextView时遇到了同样的问题,经过多次测试后,看来我在macOS 10.14上的每个基本textView都发生了错误。

我在网上搜索了多个修复程序,但没有结果。我发现最好的解决方法是将textView委托设置为其自身。然后,在didProcessEditing上,按如下所示在主线程上调用updateInsertionPointStateAndRestartTimer

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)
    }

}

答案 1 :(得分:-1)

好的,以防万一这咬人了:我已经切换到黑暗模式。显然,默认插入点是白色,因此我看不到它在白色背景下闪烁。所以我需要适当地支持暗模式。

相关问题