Skip to content

Commit 905dd90

Browse files
committed
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.
1 parent d85c396 commit 905dd90

5 files changed

Lines changed: 56 additions & 2 deletions

File tree

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3792,7 +3792,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
37923792

37933793
if (!dangerous)
37943794
++ex_normal_busy;
3795-
exec_normal(TRUE, FALSE, TRUE);
3795+
exec_normal(TRUE, lowlevel, TRUE);
37963796
if (!dangerous)
37973797
--ex_normal_busy;
37983798

src/ex_docmd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10487,12 +10487,15 @@ exec_normal_cmd(char_u *cmd, int remap, int silent)
1048710487
exec_normal(int was_typed, int use_vpeekc, int may_use_terminal_loop UNUSED)
1048810488
{
1048910489
oparg_T oa;
10490+
int c;
1049010491

10492+
// When calling vpeekc() from feedkeys() it will return Ctrl_C when there
10493+
// is nothing to get, so also check for Ctrl_C.
1049110494
clear_oparg(&oa);
1049210495
finish_op = FALSE;
1049310496
while ((!stuff_empty()
1049410497
|| ((was_typed || !typebuf_typed()) && typebuf.tb_len > 0)
10495-
|| (use_vpeekc && vpeekc() != NUL))
10498+
|| (use_vpeekc && (c = vpeekc()) != NUL && c != Ctrl_C))
1049610499
&& !got_int)
1049710500
{
1049810501
update_topline_cursor();

src/testdir/Make_all.mak

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ NEW_TESTS = \
250250
test_taglist \
251251
test_tcl \
252252
test_termencoding \
253+
test_termcodes \
253254
test_terminal \
254255
test_terminal_fail \
255256
test_textformat \
@@ -402,6 +403,7 @@ NEW_TESTS_RES = \
402403
test_tab.res \
403404
test_tcl.res \
404405
test_termencoding.res \
406+
test_termcodes.res \
405407
test_terminal.res \
406408
test_terminal_fail.res \
407409
test_textformat.res \

src/testdir/test_termcodes.vim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
" Tests for decoding escape sequences sent by the terminal.
2+
3+
" This only works for Unix in a terminal
4+
if has('gui_running') || !has('unix')
5+
finish
6+
endif
7+
8+
func Test_xterm_mouse_click()
9+
new
10+
let save_mouse = &mouse
11+
let save_term = &term
12+
let save_ttymouse = &ttymouse
13+
set mouse=a
14+
set term=xterm
15+
call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer'])
16+
redraw
17+
18+
" Xterm mouse click
19+
set ttymouse=xterm
20+
let button = 0x20 " left down
21+
let row = 2 + 32
22+
let col = 6 + 32
23+
call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')
24+
25+
let button = 0x23 " release
26+
call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')
27+
28+
call assert_equal([0, 2, 6, 0], getpos('.'))
29+
30+
" SGR mouse click
31+
set ttymouse=sgr
32+
let button = 0 " left down
33+
let row = 3
34+
let col = 9
35+
call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
36+
37+
let button = 3 " release
38+
call feedkeys(printf("\<Esc>[<%d;%d;%dm", button, col, row), 'Lx!')
39+
40+
call assert_equal([0, 3, 9, 0], getpos('.'))
41+
42+
let &mouse = save_mouse
43+
let &term = save_term
44+
let &ttymouse = save_ttymouse
45+
bwipe!
46+
endfunc
47+

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1136,
774776
/**/
775777
1135,
776778
/**/

0 commit comments

Comments
 (0)