gpt4 book ai didi

macos - 为什么应该 -[NSTextInputClient doCommandBySelector :] not pass the event up the responder chain?

转载 作者:行者123 更新时间:2023-12-03 17:47:19 24 4
gpt4 key购买 nike

TextView 不应将不可调用的命令沿着响应者链转发,the docs say对于 -[NSTextInputClient doCommandBySelector:]:

If aSelector cannot be invoked, then doCommandBySelector: should not pass this message up the responder chain. NSResponder also implements this method, and it does forward uninvokable commands up the responder chain, but a text view should not. A text view implementing the NSTextInputClient protocol inherits from NSView, which inherits from NSResponder, so your implementation of this method will override the one in NSResponder. It should not call super.

最后一句没有澄清,只是在我的文本理解没有失败的情况下重新表述了事情是如何设置的。

所以基本上只有一个处方:“ TextView 不应该”。期间。

但是为什么呢?

我可以理解一种情况,例如,您希望 TextView 不响应任何/所有 NSResponder 方法,而是将这些方法委托(delegate)给其 View Controller 。这会带来麻烦吗?这只是保持 macOS 应用程序中 TextView 行为一致的建议吗?

最佳答案

来自The Key-Input Message Sequence :

If the first responder is a text view, the key event enters the text system. The key window sends the text view a keyDown: message with the event as its argument. The keyDown: method passes the event to handleEvent:, which sends the character input to the input context for key binding and interpretation. In response, the input context sends either insertText:replacementRange:, setMarkedText:selectedRange:replacementRange:, or doCommandBySelector: to the text view.

如果 TextView 处理按键事件而 ScrollView 或其他 View 接收 doCommandBySelector: 消息,则这是不正确的。您不能将 doCommandBySelector: 发送至 super,但可以将选择器发送至委托(delegate)。

关于macos - 为什么应该 -[NSTextInputClient doCommandBySelector :] not pass the event up the responder chain?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48354363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com