feat(defaults): mouse=nvi #19290

Problem:
Since right-click can now show a popup menu, we can provide messaging to
guide users who expect 'mouse' to be disabled by default. So 'mouse' can
now be enabled by default.

Solution:
Do it.
Closes #15521
This commit is contained in:
matveyt
2022-07-17 14:14:04 +03:00
committed by GitHub
parent aae11865e1
commit eb9b93b5e0
14 changed files with 106 additions and 34 deletions

View File

@@ -441,6 +441,19 @@ You can define the special menu "PopUp". This is the menu that is displayed
when the right mouse button is pressed, if 'mousemodel' is set to popup or when the right mouse button is pressed, if 'mousemodel' is set to popup or
popup_setpos. popup_setpos.
The default "PopUp" menu is: >
aunmenu PopUp
vnoremenu PopUp.Cut "+x
vnoremenu PopUp.Copy "+y
anoremenu PopUp.Paste "+gP
vnoremenu PopUp.Paste "+P
vnoremenu PopUp.Delete "_x
nnoremenu PopUp.Select\ All> ggVG
vnoremenu PopUp.Select\ All> gg0oG$
inoremenu PopUp.Select\ All <C-Home><C-O>VG
anoremenu PopUp.-1- <Nop>
anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR>
<
Showing What Menus Are Mapped To *showing-menus* Showing What Menus Are Mapped To *showing-menus*

View File

@@ -4086,7 +4086,7 @@ A jump table for the options with a short description can be found at |Q_op|.
listing continues until finished. listing continues until finished.
*'mouse'* *'mouse'*
'mouse' string (default "") 'mouse' string (default "nvi")
global global
Enables mouse support. For example, to enable the mouse in Normal mode Enables mouse support. For example, to enable the mouse in Normal mode
@@ -4158,7 +4158,7 @@ A jump table for the options with a short description can be found at |Q_op|.
The mouse pointer is restored when the mouse is moved. The mouse pointer is restored when the mouse is moved.
*'mousemodel'* *'mousem'* *'mousemodel'* *'mousem'*
'mousemodel' 'mousem' string (default "extend") 'mousemodel' 'mousem' string (default "popup_setpos")
global global
Sets the model to use for the mouse. The name mostly specifies what Sets the model to use for the mouse. The name mostly specifies what
the right mouse button is used for: the right mouse button is used for:
@@ -4184,7 +4184,7 @@ A jump table for the options with a short description can be found at |Q_op|.
middle click paste paste middle click paste paste
In the "popup" model the right mouse button produces a pop-up menu. In the "popup" model the right mouse button produces a pop-up menu.
You need to define this first, see |popup-menu|. Nvim creates a default |popup-menu| but you can redefine it.
Note that you can further refine the meaning of buttons with mappings. Note that you can further refine the meaning of buttons with mappings.
See |mouse-overview|. But mappings are NOT used for modeless selection. See |mouse-overview|. But mappings are NOT used for modeless selection.

View File

@@ -407,7 +407,7 @@ accordingly, proceeding as follows:
Nvim started with |--embed| waits for the UI to connect before Nvim started with |--embed| waits for the UI to connect before
proceeding to load user configuration. proceeding to load user configuration.
4. Setup |default-mappings| and |default-autocmds|. 4. Setup |default-mappings| and |default-autocmds|. Create |popup-menu|.
5. Enable filetype and indent plugins. 5. Enable filetype and indent plugins.
This does the same as the command: > This does the same as the command: >

View File

@@ -52,6 +52,8 @@ centralized reference of the differences.
- 'langremap' is disabled - 'langremap' is disabled
- 'laststatus' defaults to 2 (statusline is always shown) - 'laststatus' defaults to 2 (statusline is always shown)
- 'listchars' defaults to "tab:> ,trail:-,nbsp:+" - 'listchars' defaults to "tab:> ,trail:-,nbsp:+"
- 'mouse' defaults to "nvi"
- 'mousemodel' defaults to "popup_setpos"
- 'nrformats' defaults to "bin,hex" - 'nrformats' defaults to "bin,hex"
- 'ruler' is enabled - 'ruler' is enabled
- 'sessionoptions' includes "unix,slash", excludes "options" - 'sessionoptions' includes "unix,slash", excludes "options"
@@ -78,6 +80,30 @@ centralized reference of the differences.
- |g:vimsyn_embed| defaults to "l" to enable Lua highlighting - |g:vimsyn_embed| defaults to "l" to enable Lua highlighting
Default Mouse ~
*default-mouse* *disable-mouse*
By default the mouse is enabled. The right button click opens |popup-menu|
with standard actions, such as "Cut", "Copy" and "Paste".
If you don't like this you can add to your |config| any of the following:
- ignore mouse completely >
set mouse=
<
- no |popup-menu| but the right button extends selection >
set mousemodel=extend
>
- pressing ALT+LeftMouse releases mouse until main cursor moves >
nnoremap <M-LeftMouse> <Cmd>
\ set mouse=<Bar>
\ echo 'mouse OFF until next cursor-move'<Bar>
\ autocmd CursorMoved * ++once set mouse&<Bar>
\ echo 'mouse ON'<CR>
<
Also, mouse is not in use in |command-mode| or at |more-prompt|. So if you
need to copy/paste with your terminal then just pressing ':' makes Nvim to
release the mouse cursor temporarily.
Default Mappings ~ Default Mappings ~
*default-mappings* *default-mappings*
Nvim creates the following default mappings at |startup|. You can disable any Nvim creates the following default mappings at |startup|. You can disable any

View File

@@ -810,6 +810,44 @@ function vim.deprecate(name, alternative, version, plugin, backtrace)
end end
end end
--- Create builtin mappings (incl. menus).
--- Called once on startup.
function vim._init_default_mappings()
-- mappings
--@private
local function map(mode, lhs, rhs)
vim.api.nvim_set_keymap(mode, lhs, rhs, { noremap = true, desc = 'Nvim builtin' })
end
map('n', 'Y', 'y$')
-- Use normal! <C-L> to prevent inserting raw <C-L> when using i_<C-O>. #17473
map('n', '<C-L>', '<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>')
map('i', '<C-U>', '<C-G>u<C-U>')
map('i', '<C-W>', '<C-G>u<C-W>')
map('x', '*', 'y/\\V<C-R>"<CR>')
map('x', '#', 'y?\\V<C-R>"<CR>')
-- Use : instead of <Cmd> so that ranges are supported. #19365
map('n', '&', ':&&<CR>')
-- menus
-- TODO VimScript, no l10n
vim.cmd([[
aunmenu *
vnoremenu PopUp.Cut "+x
vnoremenu PopUp.Copy "+y
anoremenu PopUp.Paste "+gP
vnoremenu PopUp.Paste "+P
vnoremenu PopUp.Delete "_x
nnoremenu PopUp.Select\ All ggVG
vnoremenu PopUp.Select\ All gg0oG$
inoremenu PopUp.Select\ All <C-Home><C-O>VG
anoremenu PopUp.-1- <Nop>
anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR>
]])
end
require('vim._meta') require('vim._meta')
return vim return vim

View File

@@ -356,7 +356,14 @@ int main(int argc, char **argv)
abort(); // unreachable abort(); // unreachable
} }
init_default_mappings(); // Default mappings. // Default mappings (incl. menus)
Error err = ERROR_INIT;
Object o = nlua_exec(STATIC_CSTR_AS_STRING("return vim._init_default_mappings()"),
(Array)ARRAY_DICT_INIT, &err);
assert(!ERROR_SET(&err));
api_clear_error(&err);
assert(o.type == kObjectTypeNil);
api_free_object(o);
TIME_MSG("init default mappings"); TIME_MSG("init default mappings");
init_default_autocmds(); init_default_autocmds();

View File

@@ -2113,24 +2113,6 @@ void f_mapcheck(typval_T *argvars, typval_T *rettv, FunPtr fptr)
get_maparg(argvars, rettv, false); get_maparg(argvars, rettv, false);
} }
void init_default_mappings(void)
{
add_map("Y", "y$", MODE_NORMAL, false);
// Use normal! <C-L> to prevent inserting raw <C-L> when using i_<C-O>
// See https://github.com/neovim/neovim/issues/17473
add_map("<C-L>", "<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>",
MODE_NORMAL, false);
add_map("<C-U>", "<C-G>u<C-U>", MODE_INSERT, false);
add_map("<C-W>", "<C-G>u<C-W>", MODE_INSERT, false);
add_map("*", "y/\\\\V<C-R>\"<CR>", MODE_VISUAL, false);
add_map("#", "y?\\\\V<C-R>\"<CR>", MODE_VISUAL, false);
// Use : instead of <Cmd> so that ranges are supported (e.g. 3& repeats the substitution on the
// next 3 lines)
add_map("&", ":&&<CR>", MODE_NORMAL, false);
}
/// Add a mapping. Unlike @ref do_map this copies the string arguments, so /// Add a mapping. Unlike @ref do_map this copies the string arguments, so
/// static or read-only strings can be used. /// static or read-only strings can be used.
/// ///

View File

@@ -1597,7 +1597,7 @@ return {
short_desc=N_("the use of mouse clicks"), short_desc=N_("the use of mouse clicks"),
type='string', list='flags', scope={'global'}, type='string', list='flags', scope={'global'},
varname='p_mouse', varname='p_mouse',
defaults={if_true=""} defaults={if_true="nvi"}
}, },
{ {
full_name='mousefocus', abbreviation='mousef', full_name='mousefocus', abbreviation='mousef',
@@ -1619,7 +1619,7 @@ return {
short_desc=N_("changes meaning of mouse buttons"), short_desc=N_("changes meaning of mouse buttons"),
type='string', scope={'global'}, type='string', scope={'global'},
varname='p_mousem', varname='p_mousem',
defaults={if_true="extend"} defaults={if_true="popup_setpos"}
}, },
{ {
full_name='mousescroll', full_name='mousescroll',

View File

@@ -524,8 +524,8 @@ describe('sysinit', function()
screen:expect([[ screen:expect([[
^ | ^ |
Entering Debug mode. Type "cont" to continue. | Entering Debug mode. Type "cont" to continue. |
pre-vimrc command line | nvim_exec() |
cmd: set noruler | cmd: aunmenu * |
> | > |
<" -u NONE -i NONE --cmd "set noruler" -D 1,1 All| <" -u NONE -i NONE --cmd "set noruler" -D 1,1 All|
| |

View File

@@ -64,6 +64,8 @@ describe('menu_get', function()
before_each(function() before_each(function()
clear() clear()
command([=[ command([=[
aunmenu *
nnoremenu &Test.Test inormal<ESC> nnoremenu &Test.Test inormal<ESC>
inoremenu Test.Test insert inoremenu Test.Test insert
vnoremenu Test.Test x vnoremenu Test.Test x
@@ -396,6 +398,7 @@ describe('menu_get', function()
before_each(function() before_each(function()
clear() clear()
command('aunmenu *')
end) end)
it('returns <keycode> representation of special keys', function() it('returns <keycode> representation of special keys', function()

View File

@@ -32,7 +32,7 @@ describe('ui/mouse/input', function()
[6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, [6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
[7] = {bold = true, foreground = Screen.colors.SeaGreen4}, [7] = {bold = true, foreground = Screen.colors.SeaGreen4},
}) })
command("set display-=msgsep") command("set display-=msgsep mousemodel=extend")
feed('itesting<cr>mouse<cr>support and selection<esc>') feed('itesting<cr>mouse<cr>support and selection<esc>')
screen:expect([[ screen:expect([[
testing | testing |

View File

@@ -63,17 +63,18 @@ describe('UI receives option updates', function()
end end
screen:attach() screen:attach()
screen:expect(function() screen:expect(function()
eq({'mouse_off'}, evs) eq({'mouse_on'}, evs)
end) end)
command("set mouse=nvi") command("set mouse=")
command("set mouse&")
screen:expect(function() screen:expect(function()
eq({'mouse_off','mouse_on'}, evs) eq({'mouse_on','mouse_off', 'mouse_on'}, evs)
end) end)
screen:detach() screen:detach()
eq({'mouse_off','mouse_on'}, evs) eq({'mouse_on','mouse_off', 'mouse_on'}, evs)
screen:attach() screen:attach()
screen:expect(function() screen:expect(function()
eq({'mouse_off','mouse_on','mouse_on'}, evs) eq({'mouse_on','mouse_off','mouse_on', 'mouse_on'}, evs)
end) end)
end) end)

View File

@@ -2367,6 +2367,7 @@ describe('builtin popupmenu', function()
call setline(1, 'popup menu test') call setline(1, 'popup menu test')
set mouse=a mousemodel=popup set mouse=a mousemodel=popup
aunmenu PopUp
menu PopUp.foo :let g:menustr = 'foo'<CR> menu PopUp.foo :let g:menustr = 'foo'<CR>
menu PopUp.bar :let g:menustr = 'bar'<CR> menu PopUp.bar :let g:menustr = 'bar'<CR>
menu PopUp.baz :let g:menustr = 'baz'<CR> menu PopUp.baz :let g:menustr = 'baz'<CR>
@@ -2554,6 +2555,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function()
call setline(1, 'popup menu test') call setline(1, 'popup menu test')
set mouse=a mousemodel=popup set mouse=a mousemodel=popup
aunmenu PopUp
menu PopUp.foo :let g:menustr = 'foo'<CR> menu PopUp.foo :let g:menustr = 'foo'<CR>
menu PopUp.bar :let g:menustr = 'bar'<CR> menu PopUp.bar :let g:menustr = 'bar'<CR>
menu PopUp.baz :let g:menustr = 'baz'<CR> menu PopUp.baz :let g:menustr = 'baz'<CR>

View File

@@ -17,7 +17,7 @@ describe('statusline clicks', function()
clear() clear()
screen = Screen.new(40, 8) screen = Screen.new(40, 8)
screen:attach() screen:attach()
command('set laststatus=2') command('set laststatus=2 mousemodel=extend')
exec([=[ exec([=[
function! MyClickFunc(minwid, clicks, button, mods) function! MyClickFunc(minwid, clicks, button, mods)
let mods = trim(a:mods) let mods = trim(a:mods)