为什么 -[NSTextInputClient doCommandBySelector:] 不应该将事件传递给响应者链?
Why should -[NSTextInputClient doCommandBySelector:] not pass the event up the responder chain?
文本视图不应将不可调用的命令转发到响应链,the docs say for -[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.
如果我对文本的理解没有让我失望,最后一句话没有澄清,只是重新说明了事情是如何设置的。
所以基本上只有一个药方:"a text view should not"。期间.
但是为什么呢?
我可以理解这样一种情况,您希望文本视图不对 any/all NSResponder
方法作出反应,而是将这些委托给它的视图控制器,例如。这会不会惹麻烦?这只是在 macOS 应用程序中保持文本视图行为一致的建议吗?
来自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.
如果文本视图处理按键事件而滚动视图或其他视图收到 doCommandBySelector:
消息,则不正确。您不能将 doCommandBySelector:
发送给 super
,但可以将选择器发送给委托人。
文本视图不应将不可调用的命令转发到响应链,the docs say for -[NSTextInputClient doCommandBySelector:]
:
If
aSelector
cannot be invoked, thendoCommandBySelector:
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 theNSTextInputClient
protocol inherits fromNSView,
which inherits fromNSResponder
, so your implementation of this method will override the one inNSResponder
. It should not call super.
如果我对文本的理解没有让我失望,最后一句话没有澄清,只是重新说明了事情是如何设置的。
所以基本上只有一个药方:"a text view should not"。期间.
但是为什么呢?
我可以理解这样一种情况,您希望文本视图不对 any/all NSResponder
方法作出反应,而是将这些委托给它的视图控制器,例如。这会不会惹麻烦?这只是在 macOS 应用程序中保持文本视图行为一致的建议吗?
来自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.
如果文本视图处理按键事件而滚动视图或其他视图收到 doCommandBySelector:
消息,则不正确。您不能将 doCommandBySelector:
发送给 super
,但可以将选择器发送给委托人。