Skip to content

Fix MMShareFindPboard and Cmd-E/Cmd-G #780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 53 additions & 45 deletions runtime/doc/gui_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Other relevant documentation:
==============================================================================
1. MacVim differences *macvim-differences*

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

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

*macvim-find*
Whenever you search for something in Vim (e.g. using "/") the search query is
copied to the OS X "Find Pasteboard". The idea is that if you search for
something and switch to another application, then you can hit <D-g> (or <D-G>)
to repeat the search in the new app. The same feature works if you search in
some app, switch to MacVim and hit <D-g>.
Whenever you search for something in Vim (e.g. using "/"), or hit <D-e> when
you have text selected, the search query is copied to the macOS "Find
Pasteboard". The idea is that if you search for something and switch to
another application, then you can hit <D-g> (or <D-G>) to repeat the search in
the new app. The same feature works if you search in some app, switch to
MacVim and hit <D-g>.

If you would like to turn off sharing Vim's search query to the macOS Find
Pasteboard, you can set |MMShareFindPboard| to "NO". Even when that's set,
<D-g> will still use the OS Find Pasteboard for searching (use |n| instead if
that's not what you want), and <D-e> ("Edit -> Use Selection for Find") will
still share the search pattern to Find Pasteboard.

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

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

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

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

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

Here is a list of relevant dictionary entries:

KEY VALUE ~
MMCellWidthMultiplier width of a normal glyph in em units [float]
MMDialogsTrackPwd open/save dialogs track the Vim pwd [bool]
MMFullScreenFadeTime fade delay for non-native fullscreen [float]
MMLoginShellArgument login shell parameter [string]
MMLoginShellCommand which shell to use to launch Vim [string]
MMNoFontSubstitution disable automatic font substitution [bool]
MMNoTitleBarWindow hide title bar [bool]
MMShareFindPboard share search text to Find Pasteboard [bool]
MMShowAddTabButton enable "add tab" button on tabline [bool]
MMTabMaxWidth maximum width of a tab [int]
MMTabMinWidth minimum width of a tab [int]
MMTabOptimumWidth default width of a tab [int]
MMTextInsetBottom text area offset in pixels [int]
MMTextInsetLeft text area offset in pixels [int]
MMTextInsetRight text area offset in pixels [int]
MMTextInsetTop text area offset in pixels [int]
MMTexturedWindow use brushed metal window (Tiger only) [bool]
MMTranslateCtrlClick interpret ctrl-click as right-click [bool]
MMUseMouseTime use mousetime to detect multiple clicks [bool]
MMVerticalSplit files open in vertical splits [bool]
MMZoomBoth zoom button maximizes both directions [bool]
*MMCellWidthMultiplier* width of a normal glyph in em units [float]
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
*MMFullScreenFadeTime* fade delay for non-native fullscreen [float]
*MMLoginShellArgument* login shell parameter [string]
*MMLoginShellCommand* which shell to use to launch Vim [string]
*MMNoFontSubstitution* disable automatic font substitution [bool]
*MMNoTitleBarWindow* hide title bar [bool]
*MMShareFindPboard* share search text to Find Pasteboard [bool]
*MMShowAddTabButton* enable "add tab" button on tabline [bool]
*MMTabMaxWidth* maximum width of a tab [int]
*MMTabMinWidth* minimum width of a tab [int]
*MMTabOptimumWidth* default width of a tab [int]
*MMTextInsetBottom* text area offset in pixels [int]
*MMTextInsetLeft* text area offset in pixels [int]
*MMTextInsetRight* text area offset in pixels [int]
*MMTextInsetTop* text area offset in pixels [int]
*MMTexturedWindow* use brushed metal window (Tiger only) [bool]
*MMTranslateCtrlClick* interpret ctrl-click as right-click [bool]
*MMUseMouseTime* use mousetime to detect multiple clicks [bool]
*MMVerticalSplit* files open in vertical splits [bool]
*MMZoomBoth* zoom button maximizes both directions [bool]

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

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

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

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

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

For example: When 'noimd' is enabled (i.e. IM is enabled) the input source is
saved when toggling between normal and insert mode, so you can use a US layout
Expand Down
21 changes: 21 additions & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -4801,6 +4801,27 @@ Macintosh os_mac.txt /*Macintosh*
Mark motion.txt /*Mark*
MenuPopup autocmd.txt /*MenuPopup*
MiNT os_mint.txt /*MiNT*
MMCellWidthMultiplier gui_mac.txt /*MMCellWidthMultiplier*
MMDialogsTrackPwd gui_mac.txt /*MMDialogsTrackPwd*
MMFullScreenFadeTime gui_mac.txt /*MMFullScreenFadeTime*
MMLoginShellArgument gui_mac.txt /*MMLoginShellArgument*
MMLoginShellCommand gui_mac.txt /*MMLoginShellCommand*
MMNoFontSubstitution gui_mac.txt /*MMNoFontSubstitution*
MMNoTitleBarWindow gui_mac.txt /*MMNoTitleBarWindow*
MMShareFindPboard gui_mac.txt /*MMShareFindPboard*
MMShowAddTabButton gui_mac.txt /*MMShowAddTabButton*
MMTabMaxWidth gui_mac.txt /*MMTabMaxWidth*
MMTabMinWidth gui_mac.txt /*MMTabMinWidth*
MMTabOptimumWidth gui_mac.txt /*MMTabOptimumWidth*
MMTextInsetBottom gui_mac.txt /*MMTextInsetBottom*
MMTextInsetLeft gui_mac.txt /*MMTextInsetLeft*
MMTextInsetRight gui_mac.txt /*MMTextInsetRight*
MMTextInsetTop gui_mac.txt /*MMTextInsetTop*
MMTexturedWindow gui_mac.txt /*MMTexturedWindow*
MMTranslateCtrlClick gui_mac.txt /*MMTranslateCtrlClick*
MMUseMouseTime gui_mac.txt /*MMUseMouseTime*
MMVerticalSplit gui_mac.txt /*MMVerticalSplit*
MMZoomBoth gui_mac.txt /*MMZoomBoth*
Moolenaar intro.txt /*Moolenaar*
MorphOS os_amiga.txt /*MorphOS*
Motif gui_x11.txt /*Motif*
Expand Down
4 changes: 2 additions & 2 deletions runtime/menu.vim
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ elseif has("gui_macvim")
vnoremenu <silent> &Edit.Find.Find\.\.\. y:promptfind <C-R>=<SID>FixFText()<CR><CR>
an 20.410.20 &Edit.Find.Find\ Next <Nop>
an 20.410.30 &Edit.Find.Find\ Previous <Nop>
vmenu 20.410.35 &Edit.Find.Use\ Selection\ for\ Find y:let @/=@"<CR>:<BS>
vnoremenu 20.410.35 &Edit.Find.Use\ Selection\ for\ Find <Nop>
else
an 20.410 &Edit.&Find<Tab>/ /
an 20.420 &Edit.Find\ and\ Rep&lace<Tab>:%s :%s/
Expand Down Expand Up @@ -1261,7 +1261,7 @@ if has("gui_macvim")
macm Edit.Find.Find\.\.\. key=<D-f>
macm Edit.Find.Find\ Next key=<D-g> action=findNext:
macm Edit.Find.Find\ Previous key=<D-G> action=findPrevious:
macm Edit.Find.Use\ Selection\ for\ Find key=<D-e>
macm Edit.Find.Use\ Selection\ for\ Find key=<D-e> action=useSelectionForFind:
macm Edit.Font.Show\ Fonts action=orderFrontFontPanel:
macm Edit.Font.Bigger key=<D-=> action=fontSizeUp:
macm Edit.Font.Smaller key=<D--> action=fontSizeDown:
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/Actions.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<string></string>
<key>findPrevious:</key>
<string></string>
<key>useSelectionForFind:</key>
<string></string>
<key>fontSizeDown:</key>
<string></string>
<key>fontSizeUp:</key>
Expand Down
4 changes: 4 additions & 0 deletions src/MacVim/MMBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern NSTimeInterval MMBalloonEvalInternalDelay;
BOOL imState;
int winposX;
int winposY;
BOOL addToFindPboardOverride;
#ifdef FEAT_BEVAL
NSString *lastToolTip;
#endif
Expand Down Expand Up @@ -155,6 +156,9 @@ extern NSTimeInterval MMBalloonEvalInternalDelay;
- (void)setWaitForAck:(BOOL)yn;
- (void)waitForConnectionAcknowledgement;

- (BOOL)addToFindPboardOverride;
- (void)clearAddToFindPboardOverride;

- (BOOL)imState;
- (void)setImState:(BOOL)activated;

Expand Down
30 changes: 30 additions & 0 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ - (int)checkForModifiedBuffers;
- (void)addInput:(NSString *)input;
- (void)redrawScreen;
- (void)handleFindReplace:(NSDictionary *)args;
- (void)useSelectionForFind;
- (void)handleMarkedText:(NSData *)data;
- (void)handleGesture:(NSData *)data;
#ifdef FEAT_BEVAL
Expand Down Expand Up @@ -254,6 +255,8 @@ - (id)init
ASLogNotice(@"Failed to load dictionaries.%@", MMSymlinkWarningString);
}

addToFindPboardOverride = NO;

return self;
}

Expand Down Expand Up @@ -1701,6 +1704,16 @@ - (oneway void)acknowledgeConnection
waitForAck = NO;
}

- (BOOL)addToFindPboardOverride
{
return addToFindPboardOverride;
}

- (void)clearAddToFindPboardOverride
{
addToFindPboardOverride = NO;
}

- (BOOL)imState
{
return imState;
Expand Down Expand Up @@ -2072,6 +2085,8 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
[self handleOpenWithArguments:[NSDictionary dictionaryWithData:data]];
} else if (FindReplaceMsgID == msgid) {
[self handleFindReplace:[NSDictionary dictionaryWithData:data]];
} else if (UseSelectionForFindMsgID == msgid) {
[self useSelectionForFind];
} else if (ZoomMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
Expand Down Expand Up @@ -2967,6 +2982,21 @@ - (void)handleFindReplace:(NSDictionary *)args
vim_free(replace);
}

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


- (void)handleMarkedText:(NSData *)data
{
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
- (IBAction)performClose:(id)sender;
- (IBAction)findNext:(id)sender;
- (IBAction)findPrevious:(id)sender;
- (IBAction)useSelectionForFind:(id)sender;
- (IBAction)vimMenuItemAction:(id)sender;
- (IBAction)vimToolbarItemAction:(id)sender;
- (IBAction)fontSizeUp:(id)sender;
Expand Down
10 changes: 6 additions & 4 deletions src/MacVim/MMWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,11 @@ - (IBAction)findPrevious:(id)sender
[self doFindNext:NO];
}

- (IBAction)useSelectionForFind:(id)sender
{
[vimController sendMessage:UseSelectionForFindMsgID data:nil];
}

- (IBAction)vimMenuItemAction:(id)sender
{
if (![sender isKindOfClass:[NSMenuItem class]]) return;
Expand Down Expand Up @@ -1582,10 +1587,7 @@ - (void)doFindNext:(BOOL)next
if ([bestType isEqual:VimFindPboardType]) {
query = [pb stringForType:VimFindPboardType];
} else {
BOOL shareFindPboard = [[NSUserDefaults standardUserDefaults]
boolForKey:MMShareFindPboardKey];
if (shareFindPboard)
query = [pb stringForType:NSStringPboardType];
query = [pb stringForType:NSStringPboardType];
}
}

Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MacVim.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ enum {
SetFullScreenColorMsgID,
ShowFindReplaceDialogMsgID,
FindReplaceMsgID,
UseSelectionForFindMsgID,
ActivateKeyScriptMsgID,
DeactivateKeyScriptMsgID,
EnableImControlMsgID,
Expand Down
Loading