# HG changeset patch # User Bram Moolenaar # Date 1554640206 -7200 # Node ID d3377393e3d97e398bae4fe76f5e25e41c7da95d # Parent b7cd0dd5cad2cc2865744a0f2c335a840aed7439 patch 8.1.1136: decoding of mouse click escape sequence is not tested commit https://github.com/vim/vim/commit/905dd905debfde403b2a18178ccc1f8e118f4f2b Author: Bram Moolenaar Date: Sun Apr 7 14:21:47 2019 +0200 patch 8.1.1136: decoding of mouse click escape sequence is not tested Problem: Decoding of mouse click escape sequence is not tested. Solution: Add a test for xterm and SGR using low-level input. Make low-level input execution with feedkeys() work. diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -3792,7 +3792,7 @@ f_feedkeys(typval_T *argvars, typval_T * if (!dangerous) ++ex_normal_busy; - exec_normal(TRUE, FALSE, TRUE); + exec_normal(TRUE, lowlevel, TRUE); if (!dangerous) --ex_normal_busy; diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -10487,12 +10487,15 @@ exec_normal_cmd(char_u *cmd, int remap, exec_normal(int was_typed, int use_vpeekc, int may_use_terminal_loop UNUSED) { oparg_T oa; - + int c; + + // When calling vpeekc() from feedkeys() it will return Ctrl_C when there + // is nothing to get, so also check for Ctrl_C. clear_oparg(&oa); finish_op = FALSE; while ((!stuff_empty() || ((was_typed || !typebuf_typed()) && typebuf.tb_len > 0) - || (use_vpeekc && vpeekc() != NUL)) + || (use_vpeekc && (c = vpeekc()) != NUL && c != Ctrl_C)) && !got_int) { update_topline_cursor(); diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -250,6 +250,7 @@ NEW_TESTS = \ test_taglist \ test_tcl \ test_termencoding \ + test_termcodes \ test_terminal \ test_terminal_fail \ test_textformat \ @@ -402,6 +403,7 @@ NEW_TESTS_RES = \ test_tab.res \ test_tcl.res \ test_termencoding.res \ + test_termcodes.res \ test_terminal.res \ test_terminal_fail.res \ test_textformat.res \ diff --git a/src/testdir/test_termcodes.vim b/src/testdir/test_termcodes.vim new file mode 100644 --- /dev/null +++ b/src/testdir/test_termcodes.vim @@ -0,0 +1,47 @@ +" Tests for decoding escape sequences sent by the terminal. + +" This only works for Unix in a terminal +if has('gui_running') || !has('unix') + finish +endif + +func Test_xterm_mouse_click() + new + let save_mouse = &mouse + let save_term = &term + let save_ttymouse = &ttymouse + set mouse=a + set term=xterm + call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer']) + redraw + + " Xterm mouse click + set ttymouse=xterm + let button = 0x20 " left down + let row = 2 + 32 + let col = 6 + 32 + call feedkeys("\[M" .. list2str([button, col, row]), 'Lx!') + + let button = 0x23 " release + call feedkeys("\[M" .. list2str([button, col, row]), 'Lx!') + + call assert_equal([0, 2, 6, 0], getpos('.')) + + " SGR mouse click + set ttymouse=sgr + let button = 0 " left down + let row = 3 + let col = 9 + call feedkeys(printf("\[<%d;%d;%dM", button, col, row), 'Lx!') + + let button = 3 " release + call feedkeys(printf("\[<%d;%d;%dm", button, col, row), 'Lx!') + + call assert_equal([0, 3, 9, 0], getpos('.')) + + let &mouse = save_mouse + let &term = save_term + let &ttymouse = save_ttymouse + bwipe! +endfunc + diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -772,6 +772,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1136, +/**/ 1135, /**/ 1134,