diff options
author | matveyt <35012635+matveyt@users.noreply.github.com> | 2022-07-17 14:14:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-17 04:14:04 -0700 |
commit | eb9b93b5e025386ec9431c9d35a4a073d6946d1d (patch) | |
tree | 4b371f7cf93aab052770590b9b995f94c8662fbd | |
parent | aae11865e1f74678a6415703ce1e076d195a2c26 (diff) | |
download | rneovim-eb9b93b5e025386ec9431c9d35a4a073d6946d1d.tar.gz rneovim-eb9b93b5e025386ec9431c9d35a4a073d6946d1d.tar.bz2 rneovim-eb9b93b5e025386ec9431c9d35a4a073d6946d1d.zip |
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
-rw-r--r-- | runtime/doc/gui.txt | 13 | ||||
-rw-r--r-- | runtime/doc/options.txt | 6 | ||||
-rw-r--r-- | runtime/doc/starting.txt | 2 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 26 | ||||
-rw-r--r-- | runtime/lua/vim/_editor.lua | 38 | ||||
-rw-r--r-- | src/nvim/main.c | 9 | ||||
-rw-r--r-- | src/nvim/mapping.c | 18 | ||||
-rw-r--r-- | src/nvim/options.lua | 4 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ex_cmds/menu_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/ui/mouse_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/options_spec.lua | 11 | ||||
-rw-r--r-- | test/functional/ui/popupmenu_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/statusline_spec.lua | 2 |
14 files changed, 106 insertions, 34 deletions
diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt index 5badd954d9..776ff228d6 100644 --- a/runtime/doc/gui.txt +++ b/runtime/doc/gui.txt @@ -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 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* diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 74ba353e0a..0f1c2051a6 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4086,7 +4086,7 @@ A jump table for the options with a short description can be found at |Q_op|. listing continues until finished. *'mouse'* -'mouse' string (default "") +'mouse' string (default "nvi") global 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. *'mousemodel'* *'mousem'* -'mousemodel' 'mousem' string (default "extend") +'mousemodel' 'mousem' string (default "popup_setpos") global Sets the model to use for the mouse. The name mostly specifies what 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 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. See |mouse-overview|. But mappings are NOT used for modeless selection. diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index 108a47c522..d57a85423c 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -407,7 +407,7 @@ accordingly, proceeding as follows: Nvim started with |--embed| waits for the UI to connect before 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. This does the same as the command: > diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index bacf160206..a74149d050 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -52,6 +52,8 @@ centralized reference of the differences. - 'langremap' is disabled - 'laststatus' defaults to 2 (statusline is always shown) - 'listchars' defaults to "tab:> ,trail:-,nbsp:+" +- 'mouse' defaults to "nvi" +- 'mousemodel' defaults to "popup_setpos" - 'nrformats' defaults to "bin,hex" - 'ruler' is enabled - '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 +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* Nvim creates the following default mappings at |startup|. You can disable any diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 7febad6ef6..c4cc151bca 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -810,6 +810,44 @@ function vim.deprecate(name, alternative, version, plugin, backtrace) 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') return vim diff --git a/src/nvim/main.c b/src/nvim/main.c index db588d4694..b06b9630e2 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -356,7 +356,14 @@ int main(int argc, char **argv) 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"); init_default_autocmds(); diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 7f4df66b4d..5a11ac686e 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2113,24 +2113,6 @@ void f_mapcheck(typval_T *argvars, typval_T *rettv, FunPtr fptr) 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 /// static or read-only strings can be used. /// diff --git a/src/nvim/options.lua b/src/nvim/options.lua index addc08d560..9e4a6a084c 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1597,7 +1597,7 @@ return { short_desc=N_("the use of mouse clicks"), type='string', list='flags', scope={'global'}, varname='p_mouse', - defaults={if_true=""} + defaults={if_true="nvi"} }, { full_name='mousefocus', abbreviation='mousef', @@ -1619,7 +1619,7 @@ return { short_desc=N_("changes meaning of mouse buttons"), type='string', scope={'global'}, varname='p_mousem', - defaults={if_true="extend"} + defaults={if_true="popup_setpos"} }, { full_name='mousescroll', diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 31aa873aa6..51ab0e6382 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -524,8 +524,8 @@ describe('sysinit', function() screen:expect([[ ^ | Entering Debug mode. Type "cont" to continue. | - pre-vimrc command line | - cmd: set noruler | + nvim_exec() | + cmd: aunmenu * | > | <" -u NONE -i NONE --cmd "set noruler" -D 1,1 All| | diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index 0cd32df27c..b9ed32c328 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -64,6 +64,8 @@ describe('menu_get', function() before_each(function() clear() command([=[ + aunmenu * + nnoremenu &Test.Test inormal<ESC> inoremenu Test.Test insert vnoremenu Test.Test x @@ -396,6 +398,7 @@ describe('menu_get', function() before_each(function() clear() + command('aunmenu *') end) it('returns <keycode> representation of special keys', function() diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index e5284894cb..69b0d1ecec 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -32,7 +32,7 @@ describe('ui/mouse/input', function() [6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, [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>') screen:expect([[ testing | diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua index 346a64c63b..c2b0bcdb64 100644 --- a/test/functional/ui/options_spec.lua +++ b/test/functional/ui/options_spec.lua @@ -63,17 +63,18 @@ describe('UI receives option updates', function() end screen:attach() screen:expect(function() - eq({'mouse_off'}, evs) + eq({'mouse_on'}, evs) end) - command("set mouse=nvi") + command("set mouse=") + command("set mouse&") screen:expect(function() - eq({'mouse_off','mouse_on'}, evs) + eq({'mouse_on','mouse_off', 'mouse_on'}, evs) end) screen:detach() - eq({'mouse_off','mouse_on'}, evs) + eq({'mouse_on','mouse_off', 'mouse_on'}, evs) screen:attach() screen:expect(function() - eq({'mouse_off','mouse_on','mouse_on'}, evs) + eq({'mouse_on','mouse_off','mouse_on', 'mouse_on'}, evs) end) end) diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 0cd991756c..7b0005bcf1 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -2367,6 +2367,7 @@ describe('builtin popupmenu', function() call setline(1, 'popup menu test') set mouse=a mousemodel=popup + aunmenu PopUp menu PopUp.foo :let g:menustr = 'foo'<CR> menu PopUp.bar :let g:menustr = 'bar'<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') set mouse=a mousemodel=popup + aunmenu PopUp menu PopUp.foo :let g:menustr = 'foo'<CR> menu PopUp.bar :let g:menustr = 'bar'<CR> menu PopUp.baz :let g:menustr = 'baz'<CR> diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index 82e669856f..1e1066d48a 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -17,7 +17,7 @@ describe('statusline clicks', function() clear() screen = Screen.new(40, 8) screen:attach() - command('set laststatus=2') + command('set laststatus=2 mousemodel=extend') exec([=[ function! MyClickFunc(minwid, clicks, button, mods) let mods = trim(a:mods) |