@@ -26,10 +26,18 @@ func MouseLeftClick(row, col)
2626 call TerminalEscapeCode (0x20 , 0 , a: row , a: col , ' M' )
2727endfunc
2828
29+ func MouseMiddleClick (row, col )
30+ call TerminalEscapeCode (0x21 , 1 , a: row , a: col , ' M' )
31+ endfunc
32+
2933func MouseLeftRelease (row, col )
3034 call TerminalEscapeCode (0x23 , 3 , a: row , a: col , ' m' )
3135endfunc
3236
37+ func MouseMiddleRelease (row, col )
38+ call TerminalEscapeCode (0x23 , 3 , a: row , a: col , ' m' )
39+ endfunc
40+
3341func MouseLeftDrag (row, col )
3442 call TerminalEscapeCode (0x43 , 0x20 , a: row , a: col , ' M' )
3543endfunc
@@ -42,7 +50,7 @@ func MouseWheelDown(row, col)
4250 call TerminalEscapeCode (0x41 , 0x41 , a: row , a: col , ' M' )
4351endfunc
4452
45- func Test_xterm_mouse_click ()
53+ func Test_xterm_mouse_left_click ()
4654 new
4755 let save_mouse = &mouse
4856 let save_term = &term
@@ -68,6 +76,48 @@ func Test_xterm_mouse_click()
6876 bwipe!
6977endfunc
7078
79+ func Test_xterm_mouse_middle_click ()
80+ new
81+ let save_mouse = &mouse
82+ let save_term = &term
83+ let save_ttymouse = &ttymouse
84+ let save_quotestar = @*
85+ let @* = ' abc'
86+ set mouse = a term = xterm
87+
88+ for ttymouse_val in [' xterm2' , ' sgr' ]
89+ let msg = ' ttymouse=' .. ttymouse_val
90+ exe ' set ttymouse=' . ttymouse_val
91+ call setline (1 , [' 123456789' , ' 123456789' ])
92+
93+ " Middle-click in the middle of the line pastes text where clicked.
94+ let row = 1
95+ let col = 6
96+ call MouseMiddleClick (row, col )
97+ call MouseMiddleRelease (row, col )
98+ call assert_equal ([' 12345abc6789' , ' 123456789' ], getline (1 , ' $' ), msg)
99+
100+ " Middle-click beyond end of the line pastes text at the end of the line.
101+ let col = 20
102+ call MouseMiddleClick (row, col )
103+ call MouseMiddleRelease (row, col )
104+ call assert_equal ([' 12345abc6789abc' , ' 123456789' ], getline (1 , ' $' ), msg)
105+
106+ " Middle-click beyond the last line pastes in the last line.
107+ let row = 5
108+ let col = 3
109+ call MouseMiddleClick (row, col )
110+ call MouseMiddleRelease (row, col )
111+ call assert_equal ([' 12345abc6789abc' , ' 12abc3456789' ], getline (1 , ' $' ), msg)
112+ endfor
113+
114+ let &mouse = save_mouse
115+ let &term = save_term
116+ let &ttymouse = save_ttymouse
117+ let @* = save_quotestar
118+ bwipe!
119+ endfunc
120+
71121func Test_xterm_mouse_wheel ()
72122 new
73123 let save_mouse = &mouse
0 commit comments