Skip to content

Commit f36a2c7

Browse files
committed
patch 8.1.2306: double and triple clicks are not tested
Problem: Double and triple clicks are not tested. Solution: Test mouse clicks to select text. (closes #5226)
1 parent e53ec39 commit f36a2c7

2 files changed

Lines changed: 90 additions & 11 deletions

File tree

src/testdir/test_termcodes.vim

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,11 @@ func Test_term_mouse_drag_to_move_tab()
674674
\ 'Tab page 2',
675675
\ ' Xtab1'], a, msg)
676676

677-
" brief sleep to avoid causing a double-click
678-
sleep 20m
677+
" Click elsewhere so that click in next iteration is not
678+
" interpreted as unwanted double-click.
679+
call MouseLeftClick(row, 11)
680+
call MouseLeftRelease(row, 11)
681+
679682
%bwipe!
680683
endfor
681684

@@ -693,24 +696,16 @@ func Test_term_mouse_double_click_to_create_tab()
693696
call test_override('no_query_mouse', 1)
694697
" Set 'mousetime' to a small value, so that double-click works but we don't
695698
" have to wait long to avoid a triple-click.
696-
set mouse=a term=xterm mousetime=100
699+
set mouse=a term=xterm mousetime=200
697700
let row = 1
698701
let col = 10
699702

700-
let round = 0
701703
for ttymouse_val in s:ttymouse_values + s:ttymouse_dec
702704
let msg = 'ttymouse=' .. ttymouse_val
703705
exe 'set ttymouse=' .. ttymouse_val
704706
e Xtab1
705707
tabnew Xtab2
706708

707-
if round > 0
708-
" We need to sleep, or else the first MouseLeftClick() will be
709-
" interpreted as a spurious triple-click.
710-
sleep 100m
711-
endif
712-
let round += 1
713-
714709
let a = split(execute(':tabs'), "\n")
715710
call assert_equal(['Tab page 1',
716711
\ ' Xtab1',
@@ -734,6 +729,11 @@ func Test_term_mouse_double_click_to_create_tab()
734729
\ 'Tab page 3',
735730
\ ' Xtab2'], a, msg)
736731

732+
" Click elsewhere so that click in next iteration is not
733+
" interpreted as unwanted double click.
734+
call MouseLeftClick(row, col + 1)
735+
call MouseLeftRelease(row, col + 1)
736+
737737
%bwipe!
738738
endfor
739739

@@ -744,6 +744,83 @@ func Test_term_mouse_double_click_to_create_tab()
744744
set mousetime&
745745
endfunc
746746

747+
" Test double/triple/quadruple click in normal mode to visually select.
748+
func Test_term_mouse_multiple_clicks_to_visually_select()
749+
let save_mouse = &mouse
750+
let save_term = &term
751+
let save_ttymouse = &ttymouse
752+
call test_override('no_query_mouse', 1)
753+
set mouse=a term=xterm mousetime=200
754+
new
755+
756+
for ttymouse_val in s:ttymouse_values + s:ttymouse_dec
757+
let msg = 'ttymouse=' .. ttymouse_val
758+
exe 'set ttymouse=' .. ttymouse_val
759+
call setline(1, ['foo [foo bar] foo', 'foo'])
760+
761+
" Double-click on word should visually select the word.
762+
call MouseLeftClick(1, 2)
763+
call assert_equal(0, getcharmod(), msg)
764+
call MouseLeftRelease(1, 2)
765+
call MouseLeftClick(1, 2)
766+
call assert_equal(32, getcharmod(), msg) " double-click
767+
call MouseLeftRelease(1, 2)
768+
call assert_equal('v', mode(), msg)
769+
norm! r1
770+
call assert_equal(['111 [foo bar] foo', 'foo'], getline(1, '$'), msg)
771+
772+
" Double-click on opening square bracket should visually
773+
" select the whole [foo bar].
774+
call MouseLeftClick(1, 5)
775+
call assert_equal(0, getcharmod(), msg)
776+
call MouseLeftRelease(1, 5)
777+
call MouseLeftClick(1, 5)
778+
call assert_equal(32, getcharmod(), msg) " double-click
779+
call MouseLeftRelease(1, 5)
780+
call assert_equal('v', mode(), msg)
781+
norm! r2
782+
call assert_equal(['111 222222222 foo', 'foo'], getline(1, '$'), msg)
783+
784+
" Triple-click should visually select the whole line.
785+
call MouseLeftClick(1, 3)
786+
call assert_equal(0, getcharmod(), msg)
787+
call MouseLeftRelease(1, 3)
788+
call MouseLeftClick(1, 3)
789+
call assert_equal(32, getcharmod(), msg) " double-click
790+
call MouseLeftRelease(1, 3)
791+
call MouseLeftClick(1, 3)
792+
call assert_equal(64, getcharmod(), msg) " triple-click
793+
call MouseLeftRelease(1, 3)
794+
call assert_equal('V', mode(), msg)
795+
norm! r3
796+
call assert_equal(['33333333333333333', 'foo'], getline(1, '$'), msg)
797+
798+
" Quadruple-click should start visual block select.
799+
call MouseLeftClick(1, 2)
800+
call assert_equal(0, getcharmod(), msg)
801+
call MouseLeftRelease(1, 2)
802+
call MouseLeftClick(1, 2)
803+
call assert_equal(32, getcharmod(), msg) " double-click
804+
call MouseLeftRelease(1, 2)
805+
call MouseLeftClick(1, 2)
806+
call assert_equal(64, getcharmod(), msg) " triple-click
807+
call MouseLeftRelease(1, 2)
808+
call MouseLeftClick(1, 2)
809+
call assert_equal(96, getcharmod(), msg) " quadruple-click
810+
call MouseLeftRelease(1, 2)
811+
call assert_equal("\<c-v>", mode(), msg)
812+
norm! r4
813+
call assert_equal(['34333333333333333', 'foo'], getline(1, '$'), msg)
814+
endfor
815+
816+
let &mouse = save_mouse
817+
let &term = save_term
818+
let &ttymouse = save_ttymouse
819+
set mousetime&
820+
call test_override('no_query_mouse', 0)
821+
bwipe!
822+
endfunc
823+
747824
func Test_xterm_mouse_click_in_fold_columns()
748825
new
749826
let save_mouse = &mouse

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2306,
744746
/**/
745747
2305,
746748
/**/

0 commit comments

Comments
 (0)