Skip to content

Commit ea5fe03

Browse files
authored
Merge pull request #780 from ychin/find-pasteboard-fixes
Fix MMShareFindPboard and Cmd-E/Cmd-G
2 parents 2c43cd6 + b3907e6 commit ea5fe03

File tree

10 files changed

+135
-53
lines changed

10 files changed

+135
-53
lines changed

runtime/doc/gui_mac.txt

+53-45
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Other relevant documentation:
3030
==============================================================================
3131
1. MacVim differences *macvim-differences*
3232

33-
One of the goals of MacVim is to make Vim behave like a proper Mac OS X
33+
One of the goals of MacVim is to make Vim behave like a proper macOS
3434
application. For this reason MacVim behaves slightly different from other GUI
3535
ports of Vim. Most of the modifications are provided in the system gvimrc
3636
file; you can quickly open this file and look at it yourself by typing: >
@@ -65,8 +65,8 @@ file at all. In this situation, you will need to set both 'encoding' and
6565
the file is read into memory, the original bytes are left untouched.
6666

6767
*macvim-shift-movement*
68-
Text editors on Mac OS X lets the user hold down shift+movement key to extend
69-
the selection. Also, pressing a printable key whilst selecting replaces the
68+
Text editors on macOS lets the user hold down shift+movement key to extend the
69+
selection. Also, pressing a printable key whilst selecting replaces the
7070
current selection with that character. MacVim can emulate this kind of
7171
behaviour (by providing key bindings and by setting 'keymodel' and
7272
'selectmode' to non-default values) although it is not enabled by default. To
@@ -120,15 +120,22 @@ These are the non-standard commands that MacVim supports:
120120
|:macaction| |:macmenu|
121121

122122
*macvim-find*
123-
Whenever you search for something in Vim (e.g. using "/") the search query is
124-
copied to the OS X "Find Pasteboard". The idea is that if you search for
125-
something and switch to another application, then you can hit <D-g> (or <D-G>)
126-
to repeat the search in the new app. The same feature works if you search in
127-
some app, switch to MacVim and hit <D-g>.
123+
Whenever you search for something in Vim (e.g. using "/"), or hit <D-e> when
124+
you have text selected, the search query is copied to the macOS "Find
125+
Pasteboard". The idea is that if you search for something and switch to
126+
another application, then you can hit <D-g> (or <D-G>) to repeat the search in
127+
the new app. The same feature works if you search in some app, switch to
128+
MacVim and hit <D-g>.
129+
130+
If you would like to turn off sharing Vim's search query to the macOS Find
131+
Pasteboard, you can set |MMShareFindPboard| to "NO". Even when that's set,
132+
<D-g> will still use the OS Find Pasteboard for searching (use |n| instead if
133+
that's not what you want), and <D-e> ("Edit -> Use Selection for Find") will
134+
still share the search pattern to Find Pasteboard.
128135

129136
Note that the command |n| is not the same as <D-g>. The former will repeat
130137
the last search made in Vim, whereas the latter searches for the string on the
131-
OS X Find Pasteboard using the action findNext: (see |:macaction|).
138+
macOS Find Pasteboard using the action findNext: (see |:macaction|).
132139

133140
The <D-g> key equivalent is a great way to bring a search from one window to
134141
another in MacVim. Simply search for something in one window (using "/") then
@@ -156,7 +163,7 @@ up the "Open with" menu. You can also drag and drop files onto the Dock icon
156163
to open them in tabs in a new window, or you can drop them in an already open
157164
window to open the files in tabs in that specific window (it is possible to
158165
have files open in e.g. splits by changing the "Open files from applications"
159-
option in the General preference pane). Finally, you can use Mac OS X System
166+
option in the General preference pane). Finally, you can use macOS System
160167
Services to open files in MacVim, see |macvim-services|.
161168

162169
Use |mvim| script to start MacVim from Terminal.
@@ -206,9 +213,9 @@ history as the window you just closed (however the next window you open will).
206213
For these reasons Quickstart is disabled by default.
207214

208215
*odbeditor* *external-editor*
209-
MacVim can act as an 'external editor' for Mac OS X applications that support
210-
the ODB Editor Protocol (or the 'external editor' protocol). Each application
211-
has different ways of configuring this option, check the application's
216+
MacVim can act as an 'external editor' for macOS applications that support the
217+
ODB Editor Protocol (or the 'external editor' protocol). Each application has
218+
different ways of configuring this option, check the application's
212219
documentation. Once configured properly MacVim can be used to open files in
213220
such an application.
214221

@@ -231,32 +238,32 @@ circumstances. These options can still be changed with the "defaults" command
231238
by opening Terminal and typing >
232239
defaults write org.vim.MacVim KEY VALUE
233240
Check the man page on "defaults" for more information on this command as well
234-
as general information regarding Mac OS X user defaults.
241+
as general information regarding macOS user defaults.
235242

236243
Here is a list of relevant dictionary entries:
237244

238245
KEY VALUE ~
239-
MMCellWidthMultiplier width of a normal glyph in em units [float]
240-
MMDialogsTrackPwd open/save dialogs track the Vim pwd [bool]
241-
MMFullScreenFadeTime fade delay for non-native fullscreen [float]
242-
MMLoginShellArgument login shell parameter [string]
243-
MMLoginShellCommand which shell to use to launch Vim [string]
244-
MMNoFontSubstitution disable automatic font substitution [bool]
245-
MMNoTitleBarWindow hide title bar [bool]
246-
MMShareFindPboard share search text to Find Pasteboard [bool]
247-
MMShowAddTabButton enable "add tab" button on tabline [bool]
248-
MMTabMaxWidth maximum width of a tab [int]
249-
MMTabMinWidth minimum width of a tab [int]
250-
MMTabOptimumWidth default width of a tab [int]
251-
MMTextInsetBottom text area offset in pixels [int]
252-
MMTextInsetLeft text area offset in pixels [int]
253-
MMTextInsetRight text area offset in pixels [int]
254-
MMTextInsetTop text area offset in pixels [int]
255-
MMTexturedWindow use brushed metal window (Tiger only) [bool]
256-
MMTranslateCtrlClick interpret ctrl-click as right-click [bool]
257-
MMUseMouseTime use mousetime to detect multiple clicks [bool]
258-
MMVerticalSplit files open in vertical splits [bool]
259-
MMZoomBoth zoom button maximizes both directions [bool]
246+
*MMCellWidthMultiplier* width of a normal glyph in em units [float]
247+
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
248+
*MMFullScreenFadeTime* fade delay for non-native fullscreen [float]
249+
*MMLoginShellArgument* login shell parameter [string]
250+
*MMLoginShellCommand* which shell to use to launch Vim [string]
251+
*MMNoFontSubstitution* disable automatic font substitution [bool]
252+
*MMNoTitleBarWindow* hide title bar [bool]
253+
*MMShareFindPboard* share search text to Find Pasteboard [bool]
254+
*MMShowAddTabButton* enable "add tab" button on tabline [bool]
255+
*MMTabMaxWidth* maximum width of a tab [int]
256+
*MMTabMinWidth* minimum width of a tab [int]
257+
*MMTabOptimumWidth* default width of a tab [int]
258+
*MMTextInsetBottom* text area offset in pixels [int]
259+
*MMTextInsetLeft* text area offset in pixels [int]
260+
*MMTextInsetRight* text area offset in pixels [int]
261+
*MMTextInsetTop* text area offset in pixels [int]
262+
*MMTexturedWindow* use brushed metal window (Tiger only) [bool]
263+
*MMTranslateCtrlClick* interpret ctrl-click as right-click [bool]
264+
*MMUseMouseTime* use mousetime to detect multiple clicks [bool]
265+
*MMVerticalSplit* files open in vertical splits [bool]
266+
*MMZoomBoth* zoom button maximizes both directions [bool]
260267

261268
As an example, if you have more than one mouse button and would wish to free
262269
up Ctrl-click so you can bind it to something else, then the appropriate
@@ -337,9 +344,9 @@ highlight color when a window becomes inactive.
337344
==============================================================================
338345
5. Menus *macvim-menus*
339346

340-
Menus in Mac OS X behave slightly different from other platforms. For that
347+
Menus in macOS behave slightly different from other platforms. For that
341348
reason two new commands have been added to Vim. To understand what these
342-
commands do you must first understand how menus work on OS X.
349+
commands do you must first understand how menus work on macOS.
343350

344351
Each entry in a menu is called a "menu item". With each menu item is
345352
associated: a title, a key equivalent and an action message. When a menu is
@@ -348,7 +355,7 @@ shown on the right. Key equivalents enable you to access a menu item using
348355
the keyboard instead of having to use the mouse. When a menu item is clicked
349356
it will send its associated action message. Actions can be used to instruct
350357
MacVim to paste some text (paste:), open a new window (newWindow:), etc.
351-
Certain actions are standard throughout OS X which is why MacVim must be able
358+
Certain actions are standard throughout macOS which is why MacVim must be able
352359
to set these for each menu item. (E.g. the menu item "Edit.Paste" must be
353360
bound to the action "paste:" otherwise pasting won't work in dialogs since
354361
that is the action that instructs them to paste something.)
@@ -440,6 +447,8 @@ Action Description ~
440447
fileOpen: Show "File Open" dialog
441448
findNext: Search forward using the "Find Pasteboard"
442449
findPrevious: Search backward using the "Find Pasteboard"
450+
useSelectionForFind: Search the selected text and share to "Find
451+
Pasteboard"
443452
fontSizeDown: Decrease font size
444453
fontSizeUp: Increase font size
445454
hide: Hide MacVim
@@ -471,7 +480,7 @@ whose name begins with "-space" ("-flexspace") and ends with "-"
471480
Toolbar icons should be tiff, png, icns, or heic, of dimension 32x32 or 24x24
472481
pixels. The larger size is used when 'tbis' is "medium" or "large", otherwise
473482
the smaller size is used (which is the default). If the icon file only
474-
contains one dimension then Mac OS X will scale the icon to the appropriate
483+
contains one dimension then macOS will scale the icon to the appropriate
475484
dimension if necessary. To avoid this, use a file format which supports
476485
multiple resolutions (such as icns) and provide both 32x32 and 24x24 versions
477486
of the icon.
@@ -532,8 +541,7 @@ outline.
532541
MacVim supports two system services. These can be accessed from the MacVim
533542
submenu in the Services menu or by right-clicking a selection. For services
534543
to work, MacVim.app should be located in the /Applications folder. (You might
535-
have to logout and then login again before Mac OS X detects the MacVim
536-
services.)
544+
have to logout and then login again before macOS detects the MacVim services.)
537545

538546
These are the currently supported services:
539547
* New MacVim Buffer With Selection: Create a new buffer and paste the
@@ -640,7 +648,7 @@ sometimes be slightly involved. Here are all the things you need to consider:
640648
- Bindings to <D-..> are case sensitive: <D-d> is not the same as <D-D>. If
641649
you want to map something to Cmd+Shift+d, then you need to use <D-D>, not
642650
<D-S-d> or <D-S-D>.
643-
- Some command key shortcuts are reserved by Mac OS X and cannot be mapped to
651+
- Some command key shortcuts are reserved by macOS and cannot be mapped to
644652
(e.g. <D-Tab>). However, some of these shortcuts can be freed up in the
645653
System Preferences under Keyboard (e.g. Cmd+Space).
646654
- A few command key mappings are set up by MacVim, see |cmd-movement|.
@@ -685,9 +693,9 @@ See the section on |key-mapping| for more help on how to map keys.
685693

686694
When editing non-English text it may be convenient to keep separate keyboard
687695
layouts for normal and insert mode. This is supported via the 'imd' option on
688-
Mac OS X 10.5 or later (on 10.4 the 'imd' option support is not as useful as
689-
it only switches between Roman and non-Roman input sources and it has been
690-
known not to work very reliably).
696+
macOS 10.5 or later (on 10.4 the 'imd' option support is not as useful as it
697+
only switches between Roman and non-Roman input sources and it has been known
698+
not to work very reliably).
691699

692700
For example: When 'noimd' is enabled (i.e. IM is enabled) the input source is
693701
saved when toggling between normal and insert mode, so you can use a US layout

runtime/doc/tags

+21
Original file line numberDiff line numberDiff line change
@@ -4801,6 +4801,27 @@ Macintosh os_mac.txt /*Macintosh*
48014801
Mark motion.txt /*Mark*
48024802
MenuPopup autocmd.txt /*MenuPopup*
48034803
MiNT os_mint.txt /*MiNT*
4804+
MMCellWidthMultiplier gui_mac.txt /*MMCellWidthMultiplier*
4805+
MMDialogsTrackPwd gui_mac.txt /*MMDialogsTrackPwd*
4806+
MMFullScreenFadeTime gui_mac.txt /*MMFullScreenFadeTime*
4807+
MMLoginShellArgument gui_mac.txt /*MMLoginShellArgument*
4808+
MMLoginShellCommand gui_mac.txt /*MMLoginShellCommand*
4809+
MMNoFontSubstitution gui_mac.txt /*MMNoFontSubstitution*
4810+
MMNoTitleBarWindow gui_mac.txt /*MMNoTitleBarWindow*
4811+
MMShareFindPboard gui_mac.txt /*MMShareFindPboard*
4812+
MMShowAddTabButton gui_mac.txt /*MMShowAddTabButton*
4813+
MMTabMaxWidth gui_mac.txt /*MMTabMaxWidth*
4814+
MMTabMinWidth gui_mac.txt /*MMTabMinWidth*
4815+
MMTabOptimumWidth gui_mac.txt /*MMTabOptimumWidth*
4816+
MMTextInsetBottom gui_mac.txt /*MMTextInsetBottom*
4817+
MMTextInsetLeft gui_mac.txt /*MMTextInsetLeft*
4818+
MMTextInsetRight gui_mac.txt /*MMTextInsetRight*
4819+
MMTextInsetTop gui_mac.txt /*MMTextInsetTop*
4820+
MMTexturedWindow gui_mac.txt /*MMTexturedWindow*
4821+
MMTranslateCtrlClick gui_mac.txt /*MMTranslateCtrlClick*
4822+
MMUseMouseTime gui_mac.txt /*MMUseMouseTime*
4823+
MMVerticalSplit gui_mac.txt /*MMVerticalSplit*
4824+
MMZoomBoth gui_mac.txt /*MMZoomBoth*
48044825
Moolenaar intro.txt /*Moolenaar*
48054826
MorphOS os_amiga.txt /*MorphOS*
48064827
Motif gui_x11.txt /*Motif*

runtime/menu.vim

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ elseif has("gui_macvim")
231231
vnoremenu <silent> &Edit.Find.Find\.\.\. y:promptfind <C-R>=<SID>FixFText()<CR><CR>
232232
an 20.410.20 &Edit.Find.Find\ Next <Nop>
233233
an 20.410.30 &Edit.Find.Find\ Previous <Nop>
234-
vmenu 20.410.35 &Edit.Find.Use\ Selection\ for\ Find y:let @/=@"<CR>:<BS>
234+
vnoremenu 20.410.35 &Edit.Find.Use\ Selection\ for\ Find <Nop>
235235
else
236236
an 20.410 &Edit.&Find<Tab>/ /
237237
an 20.420 &Edit.Find\ and\ Rep&lace<Tab>:%s :%s/
@@ -1261,7 +1261,7 @@ if has("gui_macvim")
12611261
macm Edit.Find.Find\.\.\. key=<D-f>
12621262
macm Edit.Find.Find\ Next key=<D-g> action=findNext:
12631263
macm Edit.Find.Find\ Previous key=<D-G> action=findPrevious:
1264-
macm Edit.Find.Use\ Selection\ for\ Find key=<D-e>
1264+
macm Edit.Find.Use\ Selection\ for\ Find key=<D-e> action=useSelectionForFind:
12651265
macm Edit.Font.Show\ Fonts action=orderFrontFontPanel:
12661266
macm Edit.Font.Bigger key=<D-=> action=fontSizeUp:
12671267
macm Edit.Font.Smaller key=<D--> action=fontSizeDown:

src/MacVim/Actions.plist

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<string></string>
2323
<key>findPrevious:</key>
2424
<string></string>
25+
<key>useSelectionForFind:</key>
26+
<string></string>
2527
<key>fontSizeDown:</key>
2628
<string></string>
2729
<key>fontSizeUp:</key>

src/MacVim/MMBackend.h

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern NSTimeInterval MMBalloonEvalInternalDelay;
5858
BOOL imState;
5959
int winposX;
6060
int winposY;
61+
BOOL addToFindPboardOverride;
6162
#ifdef FEAT_BEVAL
6263
NSString *lastToolTip;
6364
#endif
@@ -155,6 +156,9 @@ extern NSTimeInterval MMBalloonEvalInternalDelay;
155156
- (void)setWaitForAck:(BOOL)yn;
156157
- (void)waitForConnectionAcknowledgement;
157158

159+
- (BOOL)addToFindPboardOverride;
160+
- (void)clearAddToFindPboardOverride;
161+
158162
- (BOOL)imState;
159163
- (void)setImState:(BOOL)activated;
160164

src/MacVim/MMBackend.m

+30
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ - (int)checkForModifiedBuffers;
193193
- (void)addInput:(NSString *)input;
194194
- (void)redrawScreen;
195195
- (void)handleFindReplace:(NSDictionary *)args;
196+
- (void)useSelectionForFind;
196197
- (void)handleMarkedText:(NSData *)data;
197198
- (void)handleGesture:(NSData *)data;
198199
#ifdef FEAT_BEVAL
@@ -254,6 +255,8 @@ - (id)init
254255
ASLogNotice(@"Failed to load dictionaries.%@", MMSymlinkWarningString);
255256
}
256257

258+
addToFindPboardOverride = NO;
259+
257260
return self;
258261
}
259262

@@ -1701,6 +1704,16 @@ - (oneway void)acknowledgeConnection
17011704
waitForAck = NO;
17021705
}
17031706

1707+
- (BOOL)addToFindPboardOverride
1708+
{
1709+
return addToFindPboardOverride;
1710+
}
1711+
1712+
- (void)clearAddToFindPboardOverride
1713+
{
1714+
addToFindPboardOverride = NO;
1715+
}
1716+
17041717
- (BOOL)imState
17051718
{
17061719
return imState;
@@ -2072,6 +2085,8 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
20722085
[self handleOpenWithArguments:[NSDictionary dictionaryWithData:data]];
20732086
} else if (FindReplaceMsgID == msgid) {
20742087
[self handleFindReplace:[NSDictionary dictionaryWithData:data]];
2088+
} else if (UseSelectionForFindMsgID == msgid) {
2089+
[self useSelectionForFind];
20752090
} else if (ZoomMsgID == msgid) {
20762091
if (!data) return;
20772092
const void *bytes = [data bytes];
@@ -2967,6 +2982,21 @@ - (void)handleFindReplace:(NSDictionary *)args
29672982
vim_free(replace);
29682983
}
29692984

2985+
- (void)useSelectionForFind
2986+
{
2987+
if (VIsual_active && (State & NORMAL)) {
2988+
// This happens when Cmd-E is pressed and is supposed to be consistent
2989+
// with normal macOS apps, so it always writes to the system find
2990+
// pasteboard, unlike normal searches where it could be turned off via
2991+
// MMShareFindPboard. Set an override to make sure it gets shared out.
2992+
// Since gui_macvim_add_to_find_pboard is going to get called after
2993+
// this returns it will be responsible for calling
2994+
// clearAddToFindPboardOverride to clean up.
2995+
addToFindPboardOverride = YES;
2996+
[self addInput:@"y:let @/=@\"<CR>:<BS>"];
2997+
}
2998+
}
2999+
29703000

29713001
- (void)handleMarkedText:(NSData *)data
29723002
{

src/MacVim/MMWindowController.h

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
- (IBAction)performClose:(id)sender;
103103
- (IBAction)findNext:(id)sender;
104104
- (IBAction)findPrevious:(id)sender;
105+
- (IBAction)useSelectionForFind:(id)sender;
105106
- (IBAction)vimMenuItemAction:(id)sender;
106107
- (IBAction)vimToolbarItemAction:(id)sender;
107108
- (IBAction)fontSizeUp:(id)sender;

src/MacVim/MMWindowController.m

+6-4
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,11 @@ - (IBAction)findPrevious:(id)sender
877877
[self doFindNext:NO];
878878
}
879879

880+
- (IBAction)useSelectionForFind:(id)sender
881+
{
882+
[vimController sendMessage:UseSelectionForFindMsgID data:nil];
883+
}
884+
880885
- (IBAction)vimMenuItemAction:(id)sender
881886
{
882887
if (![sender isKindOfClass:[NSMenuItem class]]) return;
@@ -1582,10 +1587,7 @@ - (void)doFindNext:(BOOL)next
15821587
if ([bestType isEqual:VimFindPboardType]) {
15831588
query = [pb stringForType:VimFindPboardType];
15841589
} else {
1585-
BOOL shareFindPboard = [[NSUserDefaults standardUserDefaults]
1586-
boolForKey:MMShareFindPboardKey];
1587-
if (shareFindPboard)
1588-
query = [pb stringForType:NSStringPboardType];
1590+
query = [pb stringForType:NSStringPboardType];
15891591
}
15901592
}
15911593

src/MacVim/MacVim.h

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ enum {
234234
SetFullScreenColorMsgID,
235235
ShowFindReplaceDialogMsgID,
236236
FindReplaceMsgID,
237+
UseSelectionForFindMsgID,
237238
ActivateKeyScriptMsgID,
238239
DeactivateKeyScriptMsgID,
239240
EnableImControlMsgID,

0 commit comments

Comments
 (0)