From 70a98332cba2a71fe6ffb109e40877bf48e89386 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 9 Sep 2023 20:35:01 +0200 Subject: AppDelegate: Add NSTextFinder find bar Add a find bar leveraging NSTextFinder. It turns out I didn't need to do anything custom with `NSTextFinder` since `NSTextView` conveniently already has a `usesFindBar` property to turn on built-in support for it. I discovered that by looking at the TextEdit source code available here: https://developer.apple.com/library/archive/samplecode/TextEdit/Introduction/Intro.html I added an `NSScrollView` because you kind of need one to implement `NSTextFinder`. Not sure if the finding functionality would still work without the scroll view. Also use the proper `-performTextFinderAction:` selector for the "Find…" menu item to open the find bar. Now we can confirm that the "Find" menu items work correctly. --- src/MainMenu.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/MainMenu.m') diff --git a/src/MainMenu.m b/src/MainMenu.m index a961f65..afc62b6 100644 --- a/src/MainMenu.m +++ b/src/MainMenu.m @@ -358,8 +358,8 @@ NSMenuItem *MainMenuCreateEditMenuItem() @"Find…", @"Find… menu item." ) - action:@selector(performFindPanelAction:) - // action:@selector(performTextFinderAction:) + // action:@selector(performFindPanelAction:) + action:@selector(performTextFinderAction:) keyEquivalent:@"f"]; [find_ellipsis_menu_item setTag:NSTextFinderActionShowFindInterface]; // [find_ellipsis_menu_item setTag:1]; -- cgit v1.2.3