From 34ca84a2544e4b7e9083610746f7e802265b7728 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Mon, 11 Feb 2008 20:31:19 +0100 Subject: [PATCH] Find Next/Previous and Use Selection for Find menus Implemented "Find Next", "Find Previous" and "Use Selection for Find" menus. In the process the Edit->Find menu has been restructured. To accomodate these changes the code changed so that the Find Pasteboard is updated also when :set @/ = ... is called (previously the Find Pasteboard was only updated when an actual search was executed). --- src/MacVim/Actions.plist | 4 ++++ src/MacVim/MMWindowController.h | 2 ++ src/MacVim/MMWindowController.m | 46 +++++++++++++++++++++++++++++++++++++++++ src/MacVim/gvimrc | 21 ++++++++++++++++++- src/normal.c | 4 ---- src/search.c | 7 +++++++ 6 files changed, 79 insertions(+), 5 deletions(-) diff --git a/src/MacVim/Actions.plist b/src/MacVim/Actions.plist index b555ae9f..82a212f5 100644 --- a/src/MacVim/Actions.plist +++ b/src/MacVim/Actions.plist @@ -8,6 +8,10 @@ fileOpen: + findNext: + + findPrevious: + fontSizeDown: fontSizeUp: diff --git a/src/MacVim/MMWindowController.h b/src/MacVim/MMWindowController.h index f42fde41..8e8d2970 100644 --- a/src/MacVim/MMWindowController.h +++ b/src/MacVim/MMWindowController.h @@ -66,5 +66,7 @@ - (IBAction)addNewTab:(id)sender; - (IBAction)toggleToolbar:(id)sender; - (IBAction)performClose:(id)sender; +- (IBAction)findNext:(id)sender; +- (IBAction)findPrevious:(id)sender; @end diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index 9f6fe0fd..3a284936 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -79,6 +79,7 @@ - (IBAction)vimMenuItemAction:(id)sender; - (BOOL)askBackendForStarRegister:(NSPasteboard *)pb; - (void)hideTablineSeparator:(BOOL)hide; +- (void)doFindNext:(BOOL)next; @end @@ -615,6 +616,16 @@ [vimController addVimInput:@":conf q"]; } +- (IBAction)findNext:(id)sender +{ + [self doFindNext:YES]; +} + +- (IBAction)findPrevious:(id)sender +{ + [self doFindNext:NO]; +} + // -- NSWindow delegate ------------------------------------------------------ @@ -807,4 +818,39 @@ } } +- (void)doFindNext:(BOOL)next +{ + NSString *query = nil; + +#if 0 + // Use current query if the search field is selected. + id searchField = [[self searchFieldItem] view]; + if (searchField && [[searchField stringValue] length] > 0 && + [decoratedWindow firstResponder] == [searchField currentEditor]) + query = [searchField stringValue]; +#endif + + if (!query) { + // Use find pasteboard for next query. + NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSFindPboard]; + NSArray *types = [NSArray arrayWithObject:NSStringPboardType]; + if ([pb availableTypeFromArray:types]) + query = [pb stringForType:NSStringPboardType]; + } + + NSString *input = nil; + if (query) { + // NOTE: The '/' register holds the last search string. By setting it + // (using the '@/' syntax) we fool Vim into thinking that it has + // already searched for that string and then we can simply use 'n' or + // 'N' to find the next/previous match. + input = [NSString stringWithFormat:@":let @/='%@'%c", + query, next ? 'n' : 'N']; + } else { + input = next ? @"n" : @"N"; + } + + [vimController addVimInput:input]; +} + @end // MMWindowController (Private) diff --git a/src/MacVim/gvimrc b/src/MacVim/gvimrc index 433fb90c..d4780489 100644 --- a/src/MacVim/gvimrc +++ b/src/MacVim/gvimrc @@ -1,7 +1,7 @@ " System gvimrc file for MacVim " " Maintainer: Bjorn Winckler -" Last Change: Mon Oct 27 2007 +" Last Change: Mon Feb 11 2008 " " This is a work in progress. If you feel so inclined, please help me improve " this file. @@ -50,6 +50,21 @@ an 10.330 File.Close\ Window:qa :confirm qa an 10.331 File.Close :maca performClose: "an 10.331 File.Close\ Tab :tabclose + +" Edit menu + +aunmenu Edit.Find +aunmenu Edit.Find\ and\ Replace + +an 20.410.10 Edit.Find.Find\.\.\./ / +an 20.410.20 Edit.Find.Find\ Next :maca findNext: +an 20.410.30 Edit.Find.Find\ Previous :maca findPrevious: +vmenu 20.410.35 Edit.Find.Use\ Selection\ for\ Find y:let @/=@"n +an 20.410.40 Edit.Find.-SEP1- +an 20.410.50 Edit.Find.Find\ and\ Replace\.\.\.:%s :%s/ +vunmenu Edit.Find.Find\ and\ Replace\.\.\.:%s +vnoremenu Edit.Find.Find\ and\ Replace\.\.\.:s :s/ + an 20.460 Edit.-SEP4- an 20.465.10 Edit.Font.Show\ Fonts :maca orderFrontFontPanel: an 20.465.20 Edit.Font.-SEP5- @@ -189,6 +204,10 @@ macmenukey Edit.Cut macmenukey Edit.Copy macmenukey Edit.Paste macmenukey Edit.Select\ All +macmenukey Edit.Find.Find\.\.\. +macmenukey Edit.Find.Find\ Next +macmenukey Edit.Find.Find\ Previous +macmenukey Edit.Find.Use\ Selection\ for\ Find macmenukey Edit.Special\ Characters\.\.\. macmenukey Edit.Font.Bigger macmenukey Edit.Font.Smaller diff --git a/src/normal.c b/src/normal.c index acf58f87..c509d774 100644 --- a/src/normal.c +++ b/src/normal.c @@ -6111,10 +6111,6 @@ normal_search(cap, dir, pat, opt) cap->oap->use_reg_one = TRUE; curwin->w_set_curswant = TRUE; -#if FEAT_GUI_MACVIM - gui_macvim_add_to_find_pboard(pat); -#endif - i = do_search(cap->oap, dir, pat, cap->count1, opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL); if (i == 0) diff --git a/src/search.c b/src/search.c index 1ad1df31..73de100b 100644 --- a/src/search.c +++ b/src/search.c @@ -279,6 +279,9 @@ save_re_pat(idx, pat, magic) { if (spats[idx].pat != pat) { +#if FEAT_GUI_MACVIM + gui_macvim_add_to_find_pboard(pat); +#endif vim_free(spats[idx].pat); spats[idx].pat = vim_strsave(pat); spats[idx].magic = magic; @@ -422,6 +425,10 @@ set_last_search_pat(s, idx, magic, setlast) int magic; int setlast; { +#if FEAT_GUI_MACVIM + gui_macvim_add_to_find_pboard(s); +#endif + vim_free(spats[idx].pat); /* An empty string means that nothing should be matched. */ if (*s == NUL) -- 2.11.4.GIT