NSTextFinder 对 NSTextView 的操作
我试图捕获自定义 NSTextView
子类上的所有 NSTextFinderClient
调用。
显示操作在我的 -(void)performTextFinderAction:(id)sender
覆盖上调用,但对于查找下一个、查找上一个等,它不会被调用。
有什么想法吗?
谢谢!
编辑:
如果您创建一个新项目并从界面生成器中拖动 NSTextView
,command-g 和 command-shift-g(查找下一个并查找上一个)将不起作用当查找栏是第一响应者时。
这是为什么呢?
我需要 NSTextView 的自定义子类来响应每个事件的查找栏。
I'm trying to capture all the NSTextFinderClient
calls on my custom NSTextView
subclass.
The show action is called on my -(void)performTextFinderAction:(id)sender
override, but for find next, find previous, etc. it's not called.
Any ideas?
Thanks!
Edit:
If you create a new project and drag an NSTextView
from interface builder, command-g and command-shift-g (find next and find previous) don't work when the find bar is first responder.
Why is this?
I need a custom subclass of NSTextView
to respond to the find bar for every event.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 Apple 的 TextEdit 源代码中进行了搜索,因为使用 TextEdit,即使搜索字段是第一响应者,文本视图中的标准搜索栏对于 command-G(和其他快捷键)也能正常工作。
我找到了解决方案。
转到笔尖的主菜单,然后选择“查找”(和相关)菜单项。它们应该绑定到名为“performFindPanelAction:”的默认操作。现在取消绑定它们并绑定到第一响应者的“performTextFinderAction:”。
您可能在第一响应者的操作列表中找不到该操作。因此,您需要在第一响应者的属性检查器窗格中自行添加它。
下面的文件说的是这个意思
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/#//apple_ref/occ/instm/NSResponder/performTextFinderAction:
I searched in the Apple's TextEdit source code because with TextEdit, the standard search bar within the Text View works fine for command-G (and other shortcuts) even the search field is the first responder.
I found the solution.
Go to your nib for the main menu, and select the "Find" (and related) menu items. They should be bound to the default action called "performFindPanelAction:." Now unbind them and bind to "performTextFinderAction:" of the First Responder instead.
You may not find that action in the First Responder's action list. So you need to add it by yourself in the First Responder's attributes inspector pane.
This was meant by the document below saying
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/#//apple_ref/occ/instm/NSResponder/performTextFinderAction:
查找栏与客户端的 NSTextFinder 进行私下通信,而不是调用 NSResponder 的 -performTextFinderAction:。当客户以外的事物成为焦点时,这是允许 find 工作的必要条件。
你想实现什么目标?
The find bar communicates privately with the client's NSTextFinder instead of calling NSResponder's -performTextFinderAction:. This is necessary to allow find to work when something besides the client has key focus.
What are you trying to accomplish?