diff --git a/src/nvim/normal.c b/src/nvim/normal.c index d0926e6b9e..ed5f13d00a 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5740,10 +5740,10 @@ void start_selection(void) } /// Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. +/// When "c" is 'o' (checking for "mouse") then also when mapped. void may_start_select(int c) { - VIsual_select = (stuff_empty() && typebuf_typed() - && (vim_strchr(p_slm, c) != NULL)); + VIsual_select = (c == 'o' || (stuff_empty() && typebuf_typed())) && vim_strchr(p_slm, c) != NULL; } /// Start Visual mode "c". diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index a8dd0ca286..a9500f8f77 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -676,6 +676,35 @@ func Test_plug_remap() %bw! endfunc +func Test_mouse_drag_mapped_start_select() + CheckFunction test_setmouse + set mouse=a + set selectmode=key,mouse + func ClickExpr() + call test_setmouse(1, 1) + return "\" + endfunc + func DragExpr() + call test_setmouse(1, 2) + return "\" + endfunc + nnoremap ClickExpr() + nmap DragExpr() + + nnoremap + exe "normal \\" + call assert_equal('s', mode()) + exe "normal! \\" + + nunmap + nunmap + nunmap + delfunc ClickExpr + delfunc DragExpr + set selectmode& + set mouse& +endfunc + " Test for mapping in Insert mode func Test_mouse_drag_insert_map() CheckFunction test_setmouse diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index aa29698589..0f65d5eb65 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -129,10 +129,23 @@ describe('mapping', function() ]]) end) + it('dragging starts Select mode even if coming from mapping vim-patch:8.2.4806', function() + command('set mouse=a') + command('set selectmode=mouse') + + command('nnoremap ') + sleep(10) + meths.input_mouse('left', 'press', '', 0, 0, 0) + sleep(10) + meths.input_mouse('left', 'drag', '', 0, 0, 1) + sleep(10) + eq('s', eval('mode()')) + end) + it(' mapping in Insert mode works correctly vim-patch:8.2.4692', function() command('set mouse=a') - command([[inoremap let g:dragged = 1]]) + command('inoremap let g:dragged = 1') feed('i') sleep(10) meths.input_mouse('left', 'press', '', 0, 0, 0)