robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear , feed , api =n . clear , n . feed , n . api 7local insert , feed_command =n . insert , n . feed_command 8local eq , fn =t . eq , n . fn 9local poke_eventloop =n . poke_eventloop 10local command =n . command 11local exec =n . exec 12 13describe ( 'ui/mouse/input' , function () 14local function with_ext_multigrid ( multigrid ) 15local screen 16 17before_each ( function () 18clear () 19api . nvim_set_option_value ( 'mouse' , 'a' , {} ) 20api . nvim_set_option_value ( 'list' , true , {} ) 21-- NB: this is weird, but mostly irrelevant to the test 22-- So I didn't bother to change it 23command ( 'set listchars=eol:$' ) 24command ( 'setl listchars=nbsp:x' ) 25 26screen =Screen . new ( 25 , 5 , { ext_multigrid =multigrid } ) 27screen : add_extra_attr_ids { 28[ 100 ] ={ 29bold =true , 30background =Screen . colors . LightGrey , 31foreground =Screen . colors . Blue1 , 32} , 33} 34command ( 'set mousemodel=extend' ) 35feed ( 'itesting<cr>mouse<cr>support and selection<esc>' ) 36screen : expect ( { 37any ={ 38'testing ' , 39'mouse ' , 40'support and selectio%^n ' , 41} , 42} ) 43end ) 44 45it ( 'single left click moves cursor' , function () 46feed ( '<LeftMouse><2,1>' ) 47screen : expect ( { 48any ='mo%^use' , 49mouse_enabled =true , 50} ) 51feed ( '<LeftMouse><0,0>' ) 52screen : expect ( { 53any ='%^testing' , 54} ) 55end ) 56 57it ( 'middle click in Visual selection yanks, then puts' , function () 58command ( 'let g:loaded_clipboard_provider = 1' ) -- Avoid clipboard. 59feed ( '<LeftMouse><0,1>' ) 60eq ( { 2 , 0 } , api . nvim_win_get_cursor ( 0 )) 61feed ( 'viw' ) 62eq ( 'v' , fn . mode ()) 63eq ( { 2 , 4 } , api . nvim_win_get_cursor ( 0 )) 64feed ( '"a' ) -- User typed register "a. 65feed ( '<MiddleMouse><3,0>' ) 66eq ( 'mouse' , fn . getreg ( 'a' )) 67eq ( 'mouse' , fn . getreg ( '"' )) 68eq ( 'tesmouseting' , api . nvim_get_current_line ()) 69end ) 70 71it ( 'shift-click search and CTRL-T pop execute within the click' , function () 72fn . setline ( 1 , { 'foo bar' , 'x foo y' } ) 73feed ( 'gg0' ) 74feed ( '<S-LeftMouse><0,0>' ) -- "*": search for the shift-clicked word. 75eq ( { 2 , 2 } , api . nvim_win_get_cursor ( 0 )) 76eq ( '' , api . nvim_get_vvar ( 'errmsg' )) 77feed ( '<C-RightMouse><0,0>' ) -- "CTRL-T": empty tag stack raises E73. 78eq ( 'E73: Tag stack empty' , api . nvim_get_vvar ( 'errmsg' )) 79end ) 80 81it ( "in external ui works with unset 'mouse'" , function () 82api . nvim_set_option_value ( 'mouse' , '' , {} ) 83feed ( '<LeftMouse><2,1>' ) 84screen : expect ( { 85any ='mo%^use' , 86mouse_enabled =false , 87} ) 88feed ( '<LeftMouse><0,0>' ) 89screen : expect ( { 90any ='%^testing' , 91} ) 92end ) 93 94it ( 'double left click enters visual mode' , function () 95feed ( '<LeftMouse><0,0>' ) 96feed ( '<LeftRelease><0,0>' ) 97feed ( '<LeftMouse><0,0>' ) 98feed ( '<LeftRelease><0,0>' ) 99screen : expect ( { 100any ={ 101'{17:testin^g}' , 102'VISUAL' , 103} , 104} ) 105end ) 106 107it ( 'triple left click enters visual line mode' , function () 108feed ( '<LeftMouse><0,0>' ) 109feed ( '<LeftRelease><0,0>' ) 110feed ( '<LeftMouse><0,0>' ) 111feed ( '<LeftRelease><0,0>' ) 112feed ( '<LeftMouse><0,0>' ) 113feed ( '<LeftRelease><0,0>' ) 114screen : expect ( { 115any ={ 116'{17:^testing}' , 117'VISUAL LINE' , 118} , 119} ) 120end ) 121 122it ( 'quadruple left click enters visual block mode' , function () 123feed ( '<LeftMouse><0,0>' ) 124feed ( '<LeftRelease><0,0>' ) 125feed ( '<LeftMouse><0,0>' ) 126feed ( '<LeftRelease><0,0>' ) 127feed ( '<LeftMouse><0,0>' ) 128feed ( '<LeftRelease><0,0>' ) 129feed ( '<LeftMouse><0,0>' ) 130feed ( '<LeftRelease><0,0>' ) 131screen : expect ( { 132any ={ 133'{17:^t}esting' , 134'VISUAL BLOCK' , 135} , 136} ) 137end ) 138 139it ( 'double left click stays in normal mode if mouse does not contain v' , function () 140api . nvim_set_option_value ( 'mouse' , 'n' , {} ) 141 142feed ( '<LeftMouse><0,0>' ) 143feed ( '<LeftRelease><0,0>' ) 144feed ( '<LeftMouse><0,0>' ) 145feed ( '<LeftRelease><0,0>' ) 146screen : expect ( { 147any ={ 148'%^testing' , 149'mouse' , 150'support and selection' , 151} , 152mode ='normal' , 153} ) 154end ) 155 156it ( 'triple left click stays in normal mode if mouse does not contain v' , function () 157api . nvim_set_option_value ( 'mouse' , 'n' , {} ) 158 159feed ( '<LeftMouse><0,0>' ) 160feed ( '<LeftRelease><0,0>' ) 161feed ( '<LeftMouse><0,0>' ) 162feed ( '<LeftRelease><0,0>' ) 163feed ( '<LeftMouse><0,0>' ) 164feed ( '<LeftRelease><0,0>' ) 165screen : expect ( { 166any ={ 167'%^testing' , 168'mouse' , 169'support and selection' , 170} , 171mode ='normal' , 172} ) 173end ) 174 175it ( 'quadruple left click stays in normal mode if mouse does not contain v' , function () 176api . nvim_set_option_value ( 'mouse' , 'n' , {} ) 177 178feed ( '<LeftMouse><0,0>' ) 179feed ( '<LeftRelease><0,0>' ) 180feed ( '<LeftMouse><0,0>' ) 181feed ( '<LeftRelease><0,0>' ) 182feed ( '<LeftMouse><0,0>' ) 183feed ( '<LeftRelease><0,0>' ) 184feed ( '<LeftMouse><0,0>' ) 185feed ( '<LeftRelease><0,0>' ) 186screen : expect ( { 187any ={ 188'%^testing' , 189'mouse' , 190'support and selection' , 191} , 192mode ='normal' , 193} ) 194end ) 195 196describe ( 'tab drag' , function () 197it ( 'in tabline on filler space moves tab to the end' , function () 198feed_command ( '%delete' ) 199insert ( 'this is foo' ) 200feed_command ( 'silent file foo | tabnew | file bar' ) 201insert ( 'this is bar' ) 202screen : expect ( { 203any ={ 204'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 205'this is ba%^r{1:%$}' , 206} , 207} ) 208feed ( '<LeftMouse><4,0>' ) 209screen : expect ( { 210any ={ 211'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 212'this is fo%^o' , 213} , 214} ) 215feed ( '<LeftDrag><14,0>' ) 216screen : expect ( { 217any ={ 218'{24: %+ bar }{5: %+ foo }{2: }{24:X}' , 219'this is fo%^o' , 220} , 221} ) 222end ) 223 224it ( 'in tabline to the left moves tab left' , function () 225feed_command ( '%delete' ) 226insert ( 'this is foo' ) 227feed_command ( 'silent file foo | tabnew | file bar' ) 228insert ( 'this is bar' ) 229screen : expect ( { 230any ={ 231'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 232'this is ba%^r{1:%$}' , 233} , 234} ) 235feed ( '<LeftMouse><11,0>' ) 236-- Prevent the case where screen:expect() with "unchanged" returns too early, 237-- causing the click position to be overwritten by the next drag. 238poke_eventloop () 239screen : expect ( { 240any ={ 241'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 242'this is ba%^r{1:%$}' , 243} , 244unchanged =true , 245} ) 246feed ( '<LeftDrag><6,0>' ) 247screen : expect ( { 248any ={ 249'{5: %+ bar }{24: %+ foo }{2: }{24:X}' , 250'this is ba%^r{1:%$}' , 251} , 252} ) 253end ) 254 255it ( 'in tabline to the right moves tab right' , function () 256feed_command ( '%delete' ) 257insert ( 'this is foo' ) 258feed_command ( 'silent file foo | tabnew | file bar' ) 259insert ( 'this is bar' ) 260screen : expect ( { 261any ={ 262'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 263'this is ba%^r{1:%$}' , 264} , 265} ) 266feed ( '<LeftMouse><4,0>' ) 267screen : expect ( { 268any ={ 269'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 270'this is fo%^o' , 271} , 272} ) 273feed ( '<LeftDrag><7,0>' ) 274screen : expect ( { 275any ={ 276'{24: %+ bar }{5: %+ foo }{2: }{24:X}' , 277'this is fo%^o' , 278} , 279} ) 280end ) 281 282it ( 'out of tabline under filler space moves tab to the end' , function () 283feed_command ( '%delete' ) 284insert ( 'this is foo' ) 285feed_command ( 'silent file foo | tabnew | file bar' ) 286insert ( 'this is bar' ) 287screen : expect ( { 288any ={ 289'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 290'this is ba%^r{1:%$}' , 291} , 292} ) 293feed ( '<LeftMouse><4,0>' ) 294screen : expect ( { 295any ={ 296'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 297'this is fo%^o' , 298} , 299} ) 300feed ( '<LeftDrag><4,1>' ) 301screen : expect ( { 302any ={ 303'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 304'this is fo%^o' , 305} , 306unchanged =true , 307} ) 308feed ( '<LeftDrag><14,1>' ) 309screen : expect ( { 310any ={ 311'{24: %+ bar }{5: %+ foo }{2: }{24:X}' , 312'this is fo%^o' , 313} , 314} ) 315end ) 316 317it ( 'out of tabline to the left moves tab left' , function () 318feed_command ( '%delete' ) 319insert ( 'this is foo' ) 320feed_command ( 'silent file foo | tabnew | file bar' ) 321insert ( 'this is bar' ) 322screen : expect ( { 323any ={ 324'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 325'this is ba%^r{1:%$}' , 326} , 327} ) 328feed ( '<LeftMouse><11,0>' ) 329-- Prevent the case where screen:expect() with "unchanged" returns too early, 330-- causing the click position to be overwritten by the next drag. 331poke_eventloop () 332screen : expect ( { 333any ={ 334'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 335'this is ba%^r{1:%$}' , 336} , 337unchanged =true , 338} ) 339feed ( '<LeftDrag><11,1>' ) 340screen : expect ( { 341any ={ 342'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 343'this is ba%^r{1:%$}' , 344} , 345unchanged =true , 346} ) 347feed ( '<LeftDrag><6,1>' ) 348screen : expect ( { 349any ={ 350'{5: %+ bar }{24: %+ foo }{2: }{24:X}' , 351'this is ba%^r{1:%$}' , 352} , 353} ) 354end ) 355 356it ( 'out of tabline to the right moves tab right' , function () 357feed_command ( '%delete' ) 358insert ( 'this is foo' ) 359feed_command ( 'silent file foo | tabnew | file bar' ) 360insert ( 'this is bar' ) 361screen : expect ( { 362any ={ 363'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 364'this is ba%^r{1:%$}' , 365} , 366} ) 367feed ( '<LeftMouse><4,0>' ) 368screen : expect ( { 369any ={ 370'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 371'this is fo%^o' , 372} , 373} ) 374feed ( '<LeftDrag><4,1>' ) 375screen : expect ( { 376any ={ 377'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 378'this is fo%^o' , 379} , 380unchanged =true , 381} ) 382feed ( '<LeftDrag><7,1>' ) 383screen : expect ( { 384any ={ 385'{24: %+ bar }{5: %+ foo }{2: }{24:X}' , 386'this is fo%^o' , 387} , 388} ) 389end ) 390end ) 391 392describe ( 'tabline' , function () 393it ( 'left click in default tabline (tabpage label) switches to tab' , function () 394feed_command ( '%delete' ) 395insert ( 'this is foo' ) 396feed_command ( 'silent file foo | tabnew | file bar' ) 397insert ( 'this is bar' ) 398screen : expect ( { 399any ={ 400'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 401'this is ba%^r{1:%$}' , 402} , 403} ) 404feed ( '<LeftMouse><4,0>' ) 405screen : expect ( { 406any ={ 407'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 408'this is fo%^o' , 409} , 410} ) 411feed ( '<LeftMouse><6,0>' ) 412screen : expect_unchanged () 413feed ( '<LeftMouse><10,0>' ) 414screen : expect ( { 415any ={ 416'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 417'this is ba%^r{1:%$}' , 418} , 419} ) 420feed ( '<LeftMouse><12,0>' ) 421screen : expect_unchanged () 422end ) 423 424it ( 'left click in default tabline (blank space) switches tab' , function () 425feed_command ( '%delete' ) 426insert ( 'this is foo' ) 427feed_command ( 'silent file foo | tabnew | file bar' ) 428insert ( 'this is bar' ) 429screen : expect ( { 430any ={ 431'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 432'this is ba%^r{1:%$}' , 433} , 434} ) 435feed ( '<LeftMouse><20,0>' ) 436screen : expect ( { 437any ={ 438'{5: %+ foo }{24: %+ bar }{2: }{24:X}' , 439'this is fo%^o' , 440} , 441} ) 442feed ( '<LeftMouse><22,0>' ) 443screen : expect ( { 444any ={ 445'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 446'this is ba%^r{1:%$}' , 447} , 448} ) 449end ) 450 451it ( 'left click in default tabline (close label) closes tab' , function () 452api . nvim_set_option_value ( 'hidden' , true , {} ) 453feed_command ( '%delete' ) 454insert ( 'this is foo' ) 455feed_command ( 'silent file foo | tabnew | file bar' ) 456insert ( 'this is bar' ) 457screen : expect ( { 458any ={ 459'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 460'this is ba%^r{1:%$}' , 461} , 462} ) 463feed ( '<LeftMouse><24,0>' ) 464screen : expect ( { 465any ={ 466'this is fo%^o' , 467} , 468none ={ 469'{24:X}' , 470'%+ foo' , 471'%+ bar' , 472} , 473} ) 474end ) 475 476it ( 'double click in default tabline opens new tab before' , function () 477feed_command ( '%delete' ) 478insert ( 'this is foo' ) 479feed_command ( 'silent file foo | tabnew | file bar' ) 480insert ( 'this is bar' ) 481screen : expect ( { 482any ={ 483'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 484'this is ba%^r{1:%$}' , 485} , 486} ) 487feed ( '<2-LeftMouse><4,0>' ) 488screen : expect ( { 489any ={ 490'{5: Name] }{24: %+ foo %+ bar }{2: }{24:X}|' , 491'{1:%^$}' , 492} , 493} ) 494command ( 'tabclose' ) 495screen : expect ( { 496any ={ 497'{5: %+ foo }{24: %+ bar }{2: }{24:X}|' , 498'this is fo%^o' , 499} , 500} ) 501feed ( '<2-LeftMouse><20,0>' ) 502screen : expect ( { 503any ={ 504'{24: %+ foo %+ bar }{5: Name] }{2: }{24:X}' , 505'{1:%^$}' , 506} , 507} ) 508command ( 'tabclose' ) 509screen : expect ( { 510any ={ 511'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 512'this is ba%^r{1:$}' , 513} , 514} ) 515feed ( '<2-LeftMouse><10,0>' ) 516screen : expect ( { 517any ={ 518'{24: %+ foo }{5: Name] }{24: %+ bar }{2: }{24:X}' , 519'{1:%^$}' , 520} , 521} ) 522end ) 523 524describe ( '%@ label' , function () 525before_each ( function () 526feed_command ( [[ 527function Test(...) 528let g:reply = a:000 529return copy(a:000) " Check for memory leaks: return should be freed 530endfunction 531]] ) 532feed_command ( [[ 533function Test2(...) 534return call('Test', a:000 + [2]) 535endfunction 536]] ) 537api . nvim_set_option_value ( 'tabline' , '%@Test@test%X-%5@Test2@test2' , {} ) 538api . nvim_set_option_value ( 'showtabline' , 2 , {} ) 539screen : expect ( { 540any ={ 541'{2:test%-test2 }' , 542'testing' , 543'mouse' , 544'support and selectio%^n' , 545} , 546} ) 547api . nvim_set_var ( 'reply' , {} ) 548end ) 549 550local check_reply =function ( expected ) 551eq ( expected , api . nvim_get_var ( 'reply' )) 552api . nvim_set_var ( 'reply' , {} ) 553end 554 555local test_click =function ( name , click_str , click_num , mouse_button , modifiers ) 556local function doit ( do_click ) 557eq ( 1 , fn . has ( 'tablineat' )) 558do_click ( 0 , 3 ) 559check_reply ( { 0 , click_num , mouse_button , modifiers } ) 560do_click ( 0 , 4 ) 561check_reply ( {} ) 562do_click ( 0 , 6 ) 563check_reply ( { 5 , click_num , mouse_button , modifiers , 2 } ) 564do_click ( 0 , 13 ) 565check_reply ( { 5 , click_num , mouse_button , modifiers , 2 } ) 566end 567 568it ( name .. ' works (pseudokey)' , function () 569doit ( function ( row , col ) 570feed ( click_str .. '<' .. col .. ',' .. row .. '>' ) 571end ) 572end ) 573 574it ( name .. ' works (nvim_input_mouse)' , function () 575doit ( function ( row , col ) 576local buttons ={ l ='left' , m ='middle' , r ='right' } 577local modstr =( click_num > 1 ) and tostring ( click_num ) or '' 578for char in string . gmatch ( modifiers , '%w' ) do 579modstr =modstr .. char .. '-' -- - not needed but should be accepted 580end 581api . nvim_input_mouse ( buttons [ mouse_button ], 'press' , modstr , 0 , row , col ) 582end ) 583end ) 584end 585 586test_click ( 'single left click' , '<LeftMouse>' , 1 , 'l' , ' ' ) 587test_click ( 'shifted single left click' , '<S-LeftMouse>' , 1 , 'l' , 's ' ) 588test_click ( 'shifted single left click with alt modifier' , '<S-A-LeftMouse>' , 1 , 'l' , 's a ' ) 589test_click ( 590'shifted single left click with alt and ctrl modifiers' , 591'<S-C-A-LeftMouse>' , 5921 , 593'l' , 594'sca ' 595) 596-- <C-RightMouse> does not work 597test_click ( 598'shifted single right click with alt modifier' , 599'<S-A-RightMouse>' , 6001 , 601'r' , 602's a ' 603) 604-- Modifiers do not work with MiddleMouse 605test_click ( 606'shifted single middle click with alt and ctrl modifiers' , 607'<MiddleMouse>' , 6081 , 609'm' , 610' ' 611) 612-- Modifiers do not work with N-*Mouse 613test_click ( 'double left click' , '<2-LeftMouse>' , 2 , 'l' , ' ' ) 614test_click ( 'triple left click' , '<3-LeftMouse>' , 3 , 'l' , ' ' ) 615test_click ( 'quadruple left click' , '<4-LeftMouse>' , 4 , 'l' , ' ' ) 616test_click ( 'double right click' , '<2-RightMouse>' , 2 , 'r' , ' ' ) 617test_click ( 'triple right click' , '<3-RightMouse>' , 3 , 'r' , ' ' ) 618test_click ( 'quadruple right click' , '<4-RightMouse>' , 4 , 'r' , ' ' ) 619test_click ( 'double middle click' , '<2-MiddleMouse>' , 2 , 'm' , ' ' ) 620test_click ( 'triple middle click' , '<3-MiddleMouse>' , 3 , 'm' , ' ' ) 621test_click ( 'quadruple middle click' , '<4-MiddleMouse>' , 4 , 'm' , ' ' ) 622end ) 623end ) 624 625it ( 'left drag changes visual selection' , function () 626-- drag events must be preceded by a click 627feed ( '<LeftMouse><2,1>' ) 628screen : expect ( { 629any ={ 630'testing' , 631'mo%^use' , 632'support and selection' , 633} , 634} ) 635feed ( '<LeftDrag><4,1>' ) 636screen : expect ( { 637any ={ 638'testing' , 639'mo{17:us^e}' , 640'support and selection' , 641'VISUAL' , 642} , 643} ) 644feed ( '<LeftDrag><2,2>' ) 645screen : expect ( { 646any ={ 647'testing' , 648'mo{17:use}' , 649'{17:su^p}port and selection' , 650'VISUAL' , 651} , 652} ) 653feed ( '<LeftDrag><0,0>' ) 654screen : expect ( { 655any ={ 656'{17:^testing}' , 657'{17:mou}se ' , 658'support and selection' , 659'VISUAL' , 660} , 661} ) 662end ) 663 664it ( 'left drag moves cursor if mouse does not contain v' , function () 665api . nvim_set_option_value ( 'mouse' , 'n' , {} ) 666 667-- drag events must be preceded by a click 668feed ( '<LeftMouse><2,1>' ) 669screen : expect ( { 670any ={ 671'testing' , 672'mo%^use' , 673'support and selection' , 674} , 675mode ='normal' , 676} ) 677feed ( '<LeftDrag><4,1>' ) 678screen : expect ( { 679any ={ 680'testing' , 681'mous%^e' , 682'support and selection' , 683} , 684mode ='normal' , 685} ) 686feed ( '<LeftDrag><2,2>' ) 687screen : expect ( { 688any ={ 689'testing' , 690'mouse' , 691'su%^pport and selection' , 692} , 693mode ='normal' , 694} ) 695feed ( '<LeftDrag><0,0>' ) 696screen : expect ( { 697any ={ 698'%^testing' , 699'mouse' , 700'support and selection' , 701} , 702mode ='normal' , 703} ) 704end ) 705 706it ( 'left drag does not adjust existing visual selection if mouse does not contain v' , function () 707api . nvim_set_option_value ( 'mouse' , 'n' , {} ) 708 709feed ( 'gg^vlj' ) 710screen : expect ( { 711any ={ 712'{17:testing}' , 713'{17:m^o}use' , 714'support and selection' , 715'VISUAL' , 716} , 717} ) 718 719-- drag events must be preceded by a click 720feed ( '<LeftMouse><2,1>' ) 721screen : expect ( { 722any ={ 723'{17:testing}' , 724'{17:m^o}use' , 725'support and selection' , 726'VISUAL' , 727} , 728unchanged =true , 729} ) 730feed ( '<LeftDrag><4,1>' ) 731screen : expect ( { 732any ={ 733'{17:testing}' , 734'{17:m^o}use' , 735'support and selection' , 736'VISUAL' , 737} , 738unchanged =true , 739} ) 740feed ( '<LeftDrag><2,2>' ) 741screen : expect ( { 742any ={ 743'{17:testing}' , 744'{17:m^o}use' , 745'support and selection' , 746'VISUAL' , 747} , 748unchanged =true , 749} ) 750feed ( '<LeftRelease>' ) 751screen : expect ( { 752any ={ 753'{17:testing}' , 754'{17:m^o}use' , 755'support and selection' , 756'VISUAL' , 757} , 758unchanged =true , 759} ) 760end ) 761 762it ( 'left drag changes visual selection after tab click' , function () 763feed_command ( 'silent file foo | tabnew | file bar' ) 764insert ( 'this is bar' ) 765feed_command ( 'tabprevious' ) -- go to first tab 766screen : expect ( { 767any ={ 768'{5: %+ foo }{24: %+ bar }{2: }{24:X}|' , 769'testing' , 770'mouse' , 771'support and selectio%^n' , 772':tabprevious' , 773} , 774} ) 775feed ( '<LeftMouse><10,0><LeftRelease>' ) -- go to second tab 776n . poke_eventloop () 777feed ( '<LeftMouse><0,1>' ) 778-- This text is hidden when using multigrid 779local none ={ 780'mouse' , 781'support and selection' , 782} 783if multigrid then 784none =nil 785end 786screen : expect ( { 787any ={ 788'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 789'%^this is bar{1:%$}' , 790':tabprevious' , 791} , 792none =none , 793} ) 794feed ( '<LeftDrag><4,1>' ) 795screen : expect ( { 796any ={ 797'{24: %+ foo }{5: %+ bar }{2: }{24:X}' , 798'{17:this^ }is bar{1:%$}' , 799'VISUAL' , 800} , 801} ) 802end ) 803 804it ( 'left drag changes visual selection in split layout' , function () 805screen : try_resize ( 53 , 14 ) 806command ( 'set mouse=a' ) 807command ( 'vsplit' ) 808command ( 'wincmd l' ) 809command ( 'below split' ) 810command ( 'enew' ) 811feed ( 'ifoo\nbar<esc>' ) 812screen : expect ( { 813any ={ 814'foo{1:%$}' , 815'ba%^r{1:%$}' , 816} , 817} ) 818api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 6 , 27 ) 819screen : expect ( { 820any ={ 821'%^foo{1:%$}' , 822'bar{1:%$}' , 823} , 824} ) 825api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 7 , 30 ) 826screen : expect ( { 827any ={ 828'{17:foo}{100:%$}' , 829'{17:bar}{100:^$}' , 830'VISUAL' , 831} , 832} ) 833end ) 834 835it ( 'two clicks will enter VISUAL and dragging selects words' , function () 836feed ( '<LeftMouse><2,2>' ) 837feed ( '<LeftRelease><2,2>' ) 838feed ( '<LeftMouse><2,2>' ) 839screen : expect ( { 840any ={ 841'testing' , 842'mouse' , 843'{17:suppor^t} and selection' , 844'VISUAL' , 845} , 846} ) 847feed ( '<LeftDrag><0,1>' ) 848screen : expect ( { 849any ={ 850'testing' , 851'{17:^mouse}' , 852'{17:support} and selection' , 853'VISUAL' , 854} , 855} ) 856feed ( '<LeftDrag><4,0>' ) 857screen : expect ( { 858any ={ 859'{17:^testing}' , 860'{17:mouse}' , 861'{17:support} and selection' , 862'VISUAL' , 863} , 864} ) 865feed ( '<LeftDrag><14,2>' ) 866screen : expect ( { 867any ={ 868'testing' , 869'mouse' , 870'{17:support and selectio^n}' , 871'VISUAL' , 872} , 873} ) 874end ) 875 876it ( 'three clicks will enter VISUAL LINE and dragging selects lines' , function () 877feed ( '<LeftMouse><2,2>' ) 878feed ( '<LeftRelease><2,2>' ) 879feed ( '<LeftMouse><2,2>' ) 880feed ( '<LeftRelease><2,2>' ) 881feed ( '<LeftMouse><2,2>' ) 882screen : expect ( { 883any ={ 884'testing' , 885'mouse' , 886'{17:su^pport and selection}' , 887'VISUAL LINE' , 888} , 889} ) 890feed ( '<LeftDrag><0,1>' ) 891screen : expect ( { 892any ={ 893'testing' , 894'{17:^mouse}' , 895'{17:support and selection}' , 896'VISUAL LINE' , 897} , 898} ) 899feed ( '<LeftDrag><4,0>' ) 900screen : expect ( { 901any ={ 902'{17:test^ing}' , 903'{17:mouse}' , 904'{17:support and selection}' , 905'VISUAL LINE' , 906} , 907} ) 908feed ( '<LeftDrag><14,2>' ) 909screen : expect ( { 910any ={ 911'testing' , 912'mouse' , 913'{17:support and se^lection}' , 914'VISUAL LINE' , 915} , 916} ) 917end ) 918 919it ( 'four clicks will enter VISUAL BLOCK and dragging selects blockwise' , function () 920feed ( '<LeftMouse><2,2>' ) 921feed ( '<LeftRelease><2,2>' ) 922feed ( '<LeftMouse><2,2>' ) 923feed ( '<LeftRelease><2,2>' ) 924feed ( '<LeftMouse><2,2>' ) 925feed ( '<LeftRelease><2,2>' ) 926feed ( '<LeftMouse><2,2>' ) 927screen : expect ( { 928any ={ 929'testing' , 930'mouse' , 931'su{17:^p}port and selection' , 932'VISUAL BLOCK' , 933} , 934} ) 935feed ( '<LeftDrag><0,1>' ) 936screen : expect ( { 937any ={ 938'testing' , 939'{17:^mou}se' , 940'{17:sup}port and selection' , 941'VISUAL BLOCK' , 942} , 943} ) 944feed ( '<LeftDrag><4,0>' ) 945screen : expect ( { 946any ={ 947'te{17:st^i}ng' , 948'mo{17:use}' , 949'su{17:ppo}rt and selection' , 950'VISUAL BLOCK' , 951} , 952} ) 953feed ( '<LeftDrag><14,2>' ) 954screen : expect ( { 955any ={ 956'testing' , 957'mouse' , 958'su{17:pport and se^l}ection' , 959'VISUAL BLOCK' , 960} , 961} ) 962end ) 963 964it ( 'right click extends visual selection to the clicked location' , function () 965feed ( '<LeftMouse><0,0>' ) 966screen : expect ( { 967any ={ 968'%^testing' , 969'mouse' , 970'support and selection' , 971} , 972} ) 973feed ( '<RightMouse><2,2>' ) 974screen : expect ( { 975any ={ 976'{17:testing}' , 977'{17:mouse}' , 978'{17:su^p}port and selection' , 979'VISUAL' , 980} , 981} ) 982end ) 983 984it ( 'ctrl + left click places a multicursor' , function () 985command ( 'hi MCursor guifg=Black guibg=LightGrey' ) 986feed ( '<C-LeftMouse><0,0>' ) 987-- A cursor at the click; the primary cursor did not move. 988screen : expect ( { 989any ={ '{17:t}esting' , 'support and selectio^n' } , 990} ) 991feed ( 'q<BS>' ) -- remove all cursors 992end ) 993 994it ( 'g + left click will search for a tag' , function () 995api . nvim_set_option_value ( 'tags' , './non-existent-tags-file' , {} ) 996feed ( 'g<LeftMouse><0,0>' ) 997screen : expect ( { 998any ={ 999'{9:E433: No tags file}' , 1000'{9:E426: Tag not found: test}' , 1001'{9:ing}' , 1002'{6:Press ENTER or type comma}' , 1003'{6:nd to continue}%^' , 1004} , 1005} ) 1006feed ( '<cr>' ) 1007end ) 1008 1009it ( 'x1 and x2 can be triggered by api' , function () 1010api . nvim_set_var ( 'x1_pressed' , 0 ) 1011api . nvim_set_var ( 'x1_released' , 0 ) 1012api . nvim_set_var ( 'x2_pressed' , 0 ) 1013api . nvim_set_var ( 'x2_released' , 0 ) 1014command ( 'nnoremap <X1Mouse> <Cmd>let g:x1_pressed += 1<CR>' ) 1015command ( 'nnoremap <X1Release> <Cmd>let g:x1_released += 1<CR>' ) 1016command ( 'nnoremap <X2Mouse> <Cmd>let g:x2_pressed += 1<CR>' ) 1017command ( 'nnoremap <X2Release> <Cmd>let g:x2_released += 1<CR>' ) 1018api . nvim_input_mouse ( 'x1' , 'press' , '' , 0 , 0 , 0 ) 1019api . nvim_input_mouse ( 'x1' , 'release' , '' , 0 , 0 , 0 ) 1020api . nvim_input_mouse ( 'x2' , 'press' , '' , 0 , 0 , 0 ) 1021api . nvim_input_mouse ( 'x2' , 'release' , '' , 0 , 0 , 0 ) 1022eq ( 1 , api . nvim_get_var ( 'x1_pressed' ), 'x1 pressed once' ) 1023eq ( 1 , api . nvim_get_var ( 'x1_released' ), 'x1 released once' ) 1024eq ( 1 , api . nvim_get_var ( 'x2_pressed' ), 'x2 pressed once' ) 1025eq ( 1 , api . nvim_get_var ( 'x2_released' ), 'x2 released once' ) 1026end ) 1027 1028it ( 'dragging vertical separator' , function () 1029screen : try_resize ( 45 , 5 ) 1030command ( 'setlocal nowrap' ) 1031local oldwin =api . nvim_get_current_win () 1032command ( 'rightbelow vnew' ) 1033screen : expect ( { 1034any ={ 1035'testing ' , 1036'mouse ' , 1037'support and selection ' , 1038'{1:%^%$} ' , 1039'{2:%[No Name%] %[%+%] }{3:%[No Name%] }' , 1040} , 1041} ) 1042api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 22 ) 1043poke_eventloop () 1044api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 1 , 12 ) 1045screen : expect ( { 1046any ={ 1047'testing ' , 1048'mouse ' , 1049'support and ' , 1050'{1:%^$} ' , 1051'{2:< Name%] %[%+%] }{3:%[No Name%] }' , 1052} , 1053} ) 1054api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 2 , 2 ) 1055screen : expect ( { 1056any ={ 1057'te' , 1058'mo' , 1059'su' , 1060'{1:%^%$} ' , 1061'{2:< }{3:%[No Name%] }' , 1062} , 1063} ) 1064api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 2 , 2 ) 1065api . nvim_set_option_value ( 'statuscolumn' , 'foobar' , { win =oldwin } ) 1066screen : expect ( { 1067any ={ 1068'{8:fo}' , 1069'{1:%^%$} ' , 1070'{2:< }{3:%[No Name%] }' , 1071} , 1072} ) 1073api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 2 ) 1074poke_eventloop () 1075api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 1 , 12 ) 1076screen : expect ( { 1077any ={ 1078'{8:foobar}testin' , 1079'{8:foobar}mouse ' , 1080'{8:foobar}suppor' , 1081'{1:%^%$} ' , 1082'{2:< Name%] %[%+%] }{3:%[No Name%] }' , 1083} , 1084} ) 1085api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 2 , 22 ) 1086screen : expect ( { 1087any ={ 1088'{8:foobar}testing ' , 1089'{8:foobar}mouse ' , 1090'{8:foobar}support and sele' , 1091'{1:%^%$} ' , 1092'{2:%[No Name%] %[%+%] }{3:%[No Name%] }' , 1093} , 1094} ) 1095api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 2 , 22 ) 1096end ) 1097 1098local function wheel ( use_api ) 1099feed ( 'ggdG' ) 1100insert ( [[ 1101Inserting 1102text 1103with 1104many 1105lines 1106to 1107test 1108mouse scrolling 1109]] ) 1110screen : try_resize ( 53 , 14 ) 1111feed ( 'k' ) 1112api . nvim_set_option_value ( 'statuscolumn' , 'C' , { win =api . nvim_get_current_win () } ) 1113feed_command ( 'sp' ) 1114api . nvim_set_option_value ( 'statuscolumn' , 'B' , { win =api . nvim_get_current_win () } ) 1115feed_command ( 'vsp' ) 1116api . nvim_set_option_value ( 'statuscolumn' , 'A' , { win =api . nvim_get_current_win () } ) 1117screen : expect ( { 1118any ={ 1119'{8:A}lines ' , 1120'{8:A}to ' , 1121'{8:A}test ' , 1122'{8:A}^mouse scrolling ' , 1123'{8:B}lines ' , 1124'{8:B}to ' , 1125'{8:B}test ' , 1126'{8:B}mouse scrolling ' , 1127'{3:%[No Name%] %[%+%] }{2:%[No Name%] %[%+%] }' , 1128'{8:C}to ' , 1129'{8:C}test ' , 1130'{8:C}mouse scrolling ' , 1131'{2:%[No Name%] %[%+%] }' , 1132} , 1133none ={ 1134'{8:A}Inserting' , 1135'{8:A}text' , 1136'{8:A}with' , 1137'{8:A}many' , 1138'{8:B}Inserting' , 1139'{8:B}text' , 1140'{8:B}with' , 1141'{8:B}many' , 1142'{8:C}Inserting' , 1143'{8:C}text' , 1144'{8:C}with' , 1145'{8:C}many' , 1146'{8:C}lines' , 1147} , 1148} ) 1149if use_api then 1150api . nvim_input_mouse ( 'wheel' , 'down' , '' , 0 , 0 , 0 ) 1151else 1152feed ( '<ScrollWheelDown><0,0>' ) 1153end 1154screen : expect ( { 1155any ={ 1156'{8:A}^mouse scrolling ' , 1157'{8:B}lines ' , 1158'{8:B}to ' , 1159'{8:B}test ' , 1160'{8:B}mouse scrolling ' , 1161'{3:%[No Name%] %[%+%] }{2:%[No Name%] %[%+%] }' , 1162'{8:C}to ' , 1163'{8:C}test ' , 1164'{8:C}mouse scrolling ' , 1165'{2:%[No Name%] %[%+%] }' , 1166} , 1167none ={ 1168'{8:A}lines' , 1169'{8:A}to' , 1170'{8:A}test' , 1171'{8:B}Inserting' , 1172'{8:B}text' , 1173'{8:B}with' , 1174'{8:B}many' , 1175'{8:C}Inserting' , 1176'{8:C}text' , 1177'{8:C}with' , 1178'{8:C}many' , 1179'{8:C}lines' , 1180} , 1181} ) 1182if use_api then 1183api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 0 , 27 ) 1184else 1185feed ( '<ScrollWheelUp><27,0>' ) 1186end 1187screen : expect ( { 1188any ={ 1189'{8:A}^mouse scrolling ' , 1190'{8:B}lines ' , 1191'{8:B}to ' , 1192'{8:B}test ' , 1193'{3:%[No Name%] %[%+%] }{2:%[No Name%] %[%+%] }' , 1194'{8:C}to ' , 1195'{8:C}test ' , 1196'{8:C}mouse scrolling ' , 1197'{2:%[No Name%] %[%+%] }' , 1198} , 1199none ={ 1200'{8:A}Inserting' , 1201'{8:A}text' , 1202'{8:A}with' , 1203'{8:A}many' , 1204'{8:A}lines' , 1205'{8:A}to' , 1206'{8:A}test' , 1207'{8:B}Inserting' , 1208'{8:B}mouse scrolling' , 1209'{8:C}Inserting' , 1210'{8:C}text' , 1211'{8:C}with' , 1212'{8:C}many' , 1213'{8:C}lines' , 1214} , 1215} ) 1216if use_api then 1217api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 7 , 27 ) 1218api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 7 , 27 ) 1219else 1220feed ( '<ScrollWheelUp><27,7><ScrollWheelUp>' ) 1221end 1222screen : expect ( { 1223any ={ 1224'{8:A}^mouse scrolling ' , 1225'{8:B}lines ' , 1226'{8:B}to ' , 1227'{8:B}test ' , 1228'{3:%[No Name%] %[%+%] }{2:%[No Name%] %[%+%] }' , 1229'{8:C}Inserting ' , 1230'{8:C}text ' , 1231'{8:C}with ' , 1232'{8:C}many ' , 1233'{8:C}lines ' , 1234'{2:%[No Name%] %[%+%] }' , 1235} , 1236none ={ 1237'{8:A}Inserting' , 1238'{8:A}text' , 1239'{8:A}with' , 1240'{8:A}many' , 1241'{8:A}lines' , 1242'{8:A}to' , 1243'{8:A}test' , 1244'{8:B}Inserting' , 1245'{8:B}mouse scrolling' , 1246'{8:C}to' , 1247'{8:C}test' , 1248'{8:C}mouse scrolling' , 1249} , 1250} ) 1251end 1252 1253it ( 'mouse wheel will target the hovered window (pseudokey)' , function () 1254wheel ( false ) 1255end ) 1256 1257it ( 'mouse wheel will target the hovered window (nvim_input_mouse)' , function () 1258wheel ( true ) 1259end ) 1260 1261it ( 'horizontal scrolling (pseudokey)' , function () 1262command ( 'set sidescroll=0' ) 1263feed ( '<esc>:set nowrap<cr>' ) 1264 1265feed ( 'a <esc>17Ab<esc>3Ab<esc>' ) 1266screen : expect ( { 1267any ={ 1268'bbbbbbbbbbbbbbb%^b ' , 1269} , 1270} ) 1271 1272feed ( '<ScrollWheelLeft><0,0>' ) 1273screen : expect ( { 1274any ={ 1275'n bbbbbbbbbbbbbbbbbbb%^b ' , 1276} , 1277} ) 1278 1279feed ( '^<ScrollWheelRight><0,0>' ) 1280screen : expect ( { 1281any ={ 1282'g ' , 1283'%^t and selection bbbbbbbbb' , 1284} , 1285} ) 1286end ) 1287 1288it ( 'horizontal scrolling (nvim_input_mouse)' , function () 1289command ( 'set sidescroll=0' ) 1290feed ( '<esc>:set nowrap<cr>' ) 1291 1292feed ( 'a <esc>17Ab<esc>3Ab<esc>' ) 1293screen : expect ( { 1294any ={ 1295'bbbbbbbbbbbbbbb%^b ' , 1296} , 1297} ) 1298 1299api . nvim_input_mouse ( 'wheel' , 'left' , '' , 0 , 0 , 27 ) 1300screen : expect ( { 1301any ={ 1302'n bbbbbbbbbbbbbbbbbbb%^b ' , 1303} , 1304} ) 1305 1306feed ( '^' ) 1307api . nvim_input_mouse ( 'wheel' , 'right' , '' , 0 , 0 , 0 ) 1308screen : expect ( { 1309any ={ 1310'g ' , 1311'%^t and selection bbbbbbbbb' , 1312} , 1313} ) 1314end ) 1315 1316it ( "'sidescrolloff' applies to horizontal scrolling" , function () 1317command ( 'set nowrap' ) 1318command ( 'set sidescrolloff=4' ) 1319 1320feed ( 'I <esc>020ib<esc>0' ) 1321screen : expect ( { 1322any ={ 1323'testing ' , 1324'mouse ' , 1325'%^bbbbbbbbbbbbbbbbbbbb supp' , 1326} , 1327} ) 1328 1329api . nvim_input_mouse ( 'wheel' , 'right' , '' , 0 , 0 , 27 ) 1330screen : expect ( { 1331any ={ 1332'g ' , 1333' ' , 1334'bbbb%^bbbbbbbbbb support an' , 1335} , 1336} ) 1337 1338-- window-local 'sidescrolloff' should override global value. #21162 1339command ( 'setlocal sidescrolloff=2' ) 1340feed ( '0' ) 1341screen : expect ( { 1342any ={ 1343'testing ' , 1344'mouse ' , 1345'%^bbbbbbbbbbbbbbbbbbbb supp' , 1346} , 1347} ) 1348 1349api . nvim_input_mouse ( 'wheel' , 'right' , '' , 0 , 0 , 27 ) 1350screen : expect ( { 1351any ={ 1352'g ' , 1353' ' , 1354'bb%^bbbbbbbbbbbb support an' , 1355} , 1356} ) 1357end ) 1358 1359local function test_mouse_click_conceal () 1360it ( '(level 1) click on non-wrapped lines' , function () 1361feed_command ( 'let &conceallevel=1' , 'echo' ) 1362 1363feed ( '<esc><LeftMouse><0,0>' ) 1364screen : expect ( { 1365any ={ 1366'%^Section{1:>>--->--->---}{14: }t1{14: } ' , 1367'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1368'{14:>} 私は猫が大好き{1:>---}{14: X } {1:>}' , 1369} , 1370} ) 1371 1372feed ( '<esc><LeftMouse><1,0>' ) 1373screen : expect ( { 1374any ={ 1375'S%^ection{1:>>--->--->---}{14: }t1{14: } ' , 1376'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1377'{14:>} 私は猫が大好き{1:>---}{14: X } {1:>}' , 1378} , 1379} ) 1380 1381feed ( '<esc><LeftMouse><21,0>' ) 1382screen : expect ( { 1383any ={ 1384'Section{1:>>--->--->---}{14: }%^t1{14: } ' , 1385'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1386'{14:>} 私は猫が大好き{1:>---}{14: X } {1:>}' , 1387} , 1388} ) 1389 1390feed ( '<esc><LeftMouse><21,1>' ) 1391screen : expect ( { 1392any ={ 1393'Section{1:>>--->--->---}{14: }t1{14: } ' , 1394'{1:>--->--->---} {14: }t2{14: } {14: }t%^3{14: } {14: }' , 1395'{14:>} 私は猫が大好き{1:>---}{14: X } {1:>}' , 1396} , 1397} ) 1398 1399feed ( '<esc><LeftMouse><0,2>' ) 1400screen : expect ( { 1401any ={ 1402'Section{1:>>--->--->---}{14: }t1{14: } ' , 1403'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1404'{14:%^>} 私は猫が大好き{1:>---}{14: X } {1:>}' , 1405} , 1406} ) 1407 1408feed ( '<esc><LeftMouse><7,2>' ) 1409screen : expect ( { 1410any ={ 1411'Section{1:>>--->--->---}{14: }t1{14: } ' , 1412'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1413'{14:>} 私は%^猫が大好き{1:>---}{14: X } {1:>}' , 1414} , 1415} ) 1416 1417feed ( '<esc><LeftMouse><21,2>' ) 1418screen : expect ( { 1419any ={ 1420'Section{1:>>--->--->---}{14: }t1{14: } ' , 1421'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1422'{14:>} 私は猫が大好き{1:>---}{14: %^X } {1:>}' , 1423} , 1424} ) 1425end ) -- level 1 - non wrapped 1426 1427it ( '(level 1) click on wrapped lines' , function () 1428feed_command ( 'let &conceallevel=1' , 'let &wrap=1' , 'echo' ) 1429 1430feed ( '<esc><LeftMouse><24,1>' ) 1431screen : expect ( { 1432any ={ 1433'Section{1:>>--->--->---}{14: }t1{14: } ' , 1434'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14:%^ }' , 1435't4{14: } ' , 1436'{14:>} 私は猫が大好き{1:>---}{14: X} ' , 1437'{14: } ✨🐈✨ ' , 1438} , 1439} ) 1440 1441feed ( '<esc><LeftMouse><0,2>' ) 1442screen : expect ( { 1443any ={ 1444'Section{1:>>--->--->---}{14: }t1{14: } ' , 1445'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1446'%^t4{14: } ' , 1447'{14:>} 私は猫が大好き{1:>---}{14: X} ' , 1448'{14: } ✨🐈✨ ' , 1449} , 1450} ) 1451 1452feed ( '<esc><LeftMouse><8,3>' ) 1453screen : expect ( { 1454any ={ 1455'Section{1:>>--->--->---}{14: }t1{14: } ' , 1456'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1457't4{14: } ' , 1458'{14:>} 私は猫%^が大好き{1:>---}{14: X} ' , 1459'{14: } ✨🐈✨ ' , 1460} , 1461} ) 1462 1463feed ( '<esc><LeftMouse><21,3>' ) 1464screen : expect ( { 1465any ={ 1466'Section{1:>>--->--->---}{14: }t1{14: } ' , 1467'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1468't4{14: } ' , 1469'{14:>} 私は猫が大好き{1:>---}{14: %^X} ' , 1470'{14: } ✨🐈✨ ' , 1471} , 1472} ) 1473 1474feed ( '<esc><LeftMouse><4,4>' ) 1475screen : expect ( { 1476any ={ 1477'Section{1:>>--->--->---}{14: }t1{14: } ' , 1478'{1:>--->--->---} {14: }t2{14: } {14: }t3{14: } {14: }' , 1479't4{14: } ' , 1480'{14:>} 私は猫が大好き{1:>---}{14: X} ' , 1481'{14: } ✨%^🐈✨ ' , 1482} , 1483} ) 1484end ) -- level 1 - wrapped 1485 1486it ( '(level 2) click on non-wrapped lines' , function () 1487feed_command ( 'let &conceallevel=2' , 'echo' ) 1488 1489feed ( '<esc><LeftMouse><20,0>' ) 1490screen : expect ( { 1491any ={ 1492'Section{1:>>--->--->---}%^t1 ' , 1493'{1:>--->--->---} t2 t3 t4 ' , 1494'{14:>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1495} , 1496} ) 1497 1498feed ( '<esc><LeftMouse><14,1>' ) 1499screen : expect ( { 1500any ={ 1501'Section{1:>>--->--->---}t1 ' , 1502'{1:>--->--->---} %^t2 t3 t4 ' , 1503'{14:>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1504} , 1505} ) 1506 1507feed ( '<esc><LeftMouse><18,1>' ) 1508screen : expect ( { 1509any ={ 1510'Section{1:>>--->--->---}t1 ' , 1511'{1:>--->--->---} t2 t%^3 t4 ' , 1512'{14:>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1513} , 1514} ) 1515 1516feed ( '<esc><LeftMouse><0,2>' ) -- Weirdness 1517screen : expect ( { 1518any ={ 1519'Section{1:>>--->--->---}t1 ' , 1520'{1:>--->--->---} t2 t3 t4 ' , 1521'{14:%^>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1522} , 1523} ) 1524 1525feed ( '<esc><LeftMouse><8,2>' ) 1526screen : expect ( { 1527any ={ 1528'Section{1:>>--->--->---}t1 ' , 1529'{1:>--->--->---} t2 t3 t4 ' , 1530'{14:>} 私は猫%^が大好き{1:>---}{14:X} ✨{1:>}' , 1531} , 1532} ) 1533 1534feed ( '<esc><LeftMouse><20,2>' ) 1535screen : expect ( { 1536any ={ 1537'Section{1:>>--->--->---}t1 ' , 1538'{1:>--->--->---} t2 t3 t4 ' , 1539'{14:>} 私は猫が大好き{1:>---}{14:%^X} ✨{1:>}' , 1540} , 1541} ) 1542end ) -- level 2 - non wrapped 1543 1544it ( '(level 2) click on non-wrapped lines (insert mode)' , function () 1545feed_command ( 'let &conceallevel=2' , 'echo' ) 1546 1547feed ( '<esc>i<LeftMouse><20,0>' ) 1548screen : expect ( { 1549any ={ 1550'Section{1:>>--->--->---}%^t1 ' , 1551'{1:>--->--->---} t2 t3 t4 ' , 1552'{14:>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1553} , 1554} ) 1555 1556feed ( '<LeftMouse><14,1>' ) 1557screen : expect ( { 1558any ={ 1559'Section{1:>>--->--->---}t1 ' , 1560'{1:>--->--->---} %^t2 t3 t4 ' , 1561'{14:>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1562} , 1563} ) 1564 1565feed ( '<LeftMouse><18,1>' ) 1566screen : expect ( { 1567any ={ 1568'Section{1:>>--->--->---}t1 ' , 1569'{1:>--->--->---} t2 t%^3 t4 ' , 1570'{14:>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1571} , 1572} ) 1573 1574feed ( '<LeftMouse><0,2>' ) -- Weirdness 1575screen : expect ( { 1576any ={ 1577'Section{1:>>--->--->---}t1 ' , 1578'{1:>--->--->---} t2 t3 t4 ' , 1579'{14:%^>} 私は猫が大好き{1:>---}{14:X} ✨{1:>}' , 1580} , 1581} ) 1582 1583feed ( '<LeftMouse><8,2>' ) 1584screen : expect ( { 1585any ={ 1586'Section{1:>>--->--->---}t1 ' , 1587'{1:>--->--->---} t2 t3 t4 ' , 1588'{14:>} 私は猫%^が大好き{1:>---}{14:X} ✨{1:>}' , 1589} , 1590} ) 1591 1592feed ( '<LeftMouse><20,2>' ) 1593screen : expect ( { 1594any ={ 1595'Section{1:>>--->--->---}t1 ' , 1596'{1:>--->--->---} t2 t3 t4 ' , 1597'{14:>} 私は猫が大好き{1:>---}{14:%^X} ✨{1:>}' , 1598} , 1599} ) 1600end ) -- level 2 - non wrapped (insert mode) 1601 1602it ( '(level 2) click on wrapped lines' , function () 1603feed_command ( 'let &conceallevel=2' , 'let &wrap=1' , 'echo' ) 1604 1605feed ( '<esc><LeftMouse><20,0>' ) 1606screen : expect ( { 1607any ={ 1608'Section{1:>>--->--->---}%^t1 ' , 1609'{1:>--->--->---} t2 t3 ' , 1610't4 ' , 1611'{14:>} 私は猫が大好き{1:>---}{14:X} ' , 1612' ✨🐈✨ ' , 1613} , 1614} ) 1615 1616feed ( '<esc><LeftMouse><14,1>' ) 1617screen : expect ( { 1618any ={ 1619'Section{1:>>--->--->---}t1 ' , 1620'{1:>--->--->---} %^t2 t3 ' , 1621't4 ' , 1622'{14:>} 私は猫が大好き{1:>---}{14:X} ' , 1623' ✨🐈✨ ' , 1624} , 1625} ) 1626 1627feed ( '<esc><LeftMouse><18,1>' ) 1628screen : expect ( { 1629any ={ 1630'Section{1:>>--->--->---}t1 ' , 1631'{1:>--->--->---} t2 t%^3 ' , 1632't4 ' , 1633'{14:>} 私は猫が大好き{1:>---}{14:X} ' , 1634' ✨🐈✨ ' , 1635} , 1636} ) 1637 1638-- NOTE: The click would ideally be on the 't' in 't4', but wrapping 1639-- caused the invisible '*' right before 't4' to remain on the previous 1640-- screen line. This is being treated as expected because fixing this is 1641-- out of scope for mouse clicks. Should the wrapping behavior of 1642-- concealed characters change in the future, this case should be 1643-- reevaluated. 1644feed ( '<esc><LeftMouse><0,2>' ) 1645screen : expect ( { 1646any ={ 1647'Section{1:>>--->--->---}t1 ' , 1648'{1:>--->--->---} t2 t3 %^ ' , 1649't4 ' , 1650'{14:>} 私は猫が大好き{1:>---}{14:X} ' , 1651' ✨🐈✨ ' , 1652} , 1653} ) 1654 1655feed ( '<esc><LeftMouse><1,2>' ) 1656screen : expect ( { 1657any ={ 1658'Section{1:>>--->--->---}t1 ' , 1659'{1:>--->--->---} t2 t3 ' , 1660't%^4 ' , 1661'{14:>} 私は猫が大好き{1:>---}{14:X} ' , 1662' ✨🐈✨ ' , 1663} , 1664} ) 1665 1666feed ( '<esc><LeftMouse><0,3>' ) 1667screen : expect ( { 1668any ={ 1669'Section{1:>>--->--->---}t1 ' , 1670'{1:>--->--->---} t2 t3 ' , 1671't4 ' , 1672'{14:%^>} 私は猫が大好き{1:>---}{14:X} ' , 1673' ✨🐈✨ ' , 1674} , 1675} ) 1676 1677feed ( '<esc><LeftMouse><20,3>' ) 1678screen : expect ( { 1679any ={ 1680'Section{1:>>--->--->---}t1 ' , 1681'{1:>--->--->---} t2 t3 ' , 1682't4 ' , 1683'{14:>} 私は猫が大好き{1:>---}{14:%^X} ' , 1684' ✨🐈✨ ' , 1685} , 1686} ) 1687 1688feed ( '<esc><LeftMouse><1,4>' ) 1689screen : expect ( { 1690any ={ 1691'Section{1:>>--->--->---}t1 ' , 1692'{1:>--->--->---} t2 t3 ' , 1693't4 ' , 1694'{14:>} 私は猫が大好き{1:>---}{14:X} ' , 1695'%^✨🐈✨ ' , 1696} , 1697} ) 1698 1699feed ( '<esc><LeftMouse><5,4>' ) 1700screen : expect ( { 1701any ={ 1702'Section{1:>>--->--->---}t1 ' , 1703'{1:>--->--->---} t2 t3 ' , 1704't4 ' , 1705'{14:>} 私は猫が大好き{1:>---}{14:X} ' , 1706'✨🐈%^✨ ' , 1707} , 1708} ) 1709end ) -- level 2 - wrapped 1710 1711it ( '(level 3) click on non-wrapped lines' , function () 1712feed_command ( 'let &conceallevel=3' , 'echo' ) 1713 1714feed ( '<esc><LeftMouse><0,2>' ) 1715screen : expect ( { 1716any ={ 1717'Section{1:>>--->--->---}t1 ' , 1718'{1:>--->--->---} t2 t3 t4 ' , 1719'%^ 私は猫が大好き{1:>----} ✨🐈' , 1720} , 1721} ) 1722 1723feed ( '<esc><LeftMouse><1,2>' ) 1724screen : expect ( { 1725any ={ 1726'Section{1:>>--->--->---}t1 ' , 1727'{1:>--->--->---} t2 t3 t4 ' , 1728' %^私は猫が大好き{1:>----} ✨🐈' , 1729} , 1730} ) 1731 1732feed ( '<esc><LeftMouse><13,2>' ) 1733screen : expect ( { 1734any ={ 1735'Section{1:>>--->--->---}t1 ' , 1736'{1:>--->--->---} t2 t3 t4 ' , 1737' 私は猫が大好%^き{1:>----} ✨🐈' , 1738} , 1739} ) 1740 1741feed ( '<esc><LeftMouse><20,2>' ) 1742feed ( 'zH' ) -- FIXME: unnecessary horizontal scrolling 1743screen : expect ( { 1744any ={ 1745'Section{1:>>--->--->---}t1 ' , 1746'{1:>--->--->---} t2 t3 t4 ' , 1747' 私は猫が大好き{1:>----}%^ ✨🐈' , 1748} , 1749} ) 1750end ) -- level 3 - non wrapped 1751 1752it ( '(level 3) click on wrapped lines' , function () 1753feed_command ( 'let &conceallevel=3' , 'let &wrap=1' , 'echo' ) 1754 1755feed ( '<esc><LeftMouse><14,1>' ) 1756screen : expect ( { 1757any ={ 1758'Section{1:>>--->--->---}t1 ' , 1759'{1:>--->--->---} %^t2 t3 ' , 1760't4 ' , 1761' 私は猫が大好き{1:>----} ' , 1762' ✨🐈✨ ' , 1763} , 1764} ) 1765 1766feed ( '<esc><LeftMouse><18,1>' ) 1767screen : expect ( { 1768any ={ 1769'Section{1:>>--->--->---}t1 ' , 1770'{1:>--->--->---} t2 t%^3 ' , 1771't4 ' , 1772' 私は猫が大好き{1:>----} ' , 1773' ✨🐈✨ ' , 1774} , 1775} ) 1776 1777feed ( '<esc><LeftMouse><1,2>' ) 1778screen : expect ( { 1779any ={ 1780'Section{1:>>--->--->---}t1 ' , 1781'{1:>--->--->---} t2 t3 ' , 1782't%^4 ' , 1783' 私は猫が大好き{1:>----} ' , 1784' ✨🐈✨ ' , 1785} , 1786} ) 1787 1788feed ( '<esc><LeftMouse><0,3>' ) 1789screen : expect ( { 1790any ={ 1791'Section{1:>>--->--->---}t1 ' , 1792'{1:>--->--->---} t2 t3 ' , 1793't4 ' , 1794'%^ 私は猫が大好き{1:>----} ' , 1795' ✨🐈✨ ' , 1796} , 1797} ) 1798 1799feed ( '<esc><LeftMouse><20,3>' ) 1800screen : expect ( { 1801any ={ 1802'Section{1:>>--->--->---}t1 ' , 1803'{1:>--->--->---} t2 t3 ' , 1804't4 ' , 1805' 私は猫が大好き{1:>----}%^ ' , 1806' ✨🐈✨ ' , 1807} , 1808} ) 1809 1810feed ( '<esc><LeftMouse><1,4>' ) 1811screen : expect ( { 1812any ={ 1813'Section{1:>>--->--->---}t1 ' , 1814'{1:>--->--->---} t2 t3 ' , 1815't4 ' , 1816' 私は猫が大好き{1:>----} ' , 1817' %^✨🐈✨ ' , 1818} , 1819} ) 1820 1821feed ( '<esc><LeftMouse><3,4>' ) 1822screen : expect ( { 1823any ={ 1824'Section{1:>>--->--->---}t1 ' , 1825'{1:>--->--->---} t2 t3 ' , 1826't4 ' , 1827' 私は猫が大好き{1:>----} ' , 1828' ✨%^🐈✨ ' , 1829} , 1830} ) 1831 1832feed ( '<esc><LeftMouse><5,4>' ) 1833screen : expect ( { 1834any ={ 1835'Section{1:>>--->--->---}t1 ' , 1836'{1:>--->--->---} t2 t3 ' , 1837't4 ' , 1838' 私は猫が大好き{1:>----} ' , 1839' ✨🐈%^✨ ' , 1840} , 1841} ) 1842end ) -- level 3 - wrapped 1843end 1844 1845describe ( 'on concealed text' , function () 1846-- Helpful for reading the test expectations: 1847-- :match Error /\^/ 1848 1849before_each ( function () 1850screen : try_resize ( 25 , 7 ) 1851feed ( 'ggdG' ) 1852 1853command ( [[setlocal concealcursor=ni nowrap shiftwidth=2 tabstop=4 list listchars=tab:>-]] ) 1854command ( [[highlight link X0 Normal]] ) 1855command ( [[highlight link X1 NonText]] ) 1856command ( [[highlight link X2 NonText]] ) 1857command ( [[highlight link X3 NonText]] ) 1858 1859-- First column is there to retain the tabs. 1860insert ( [[ 1861|Section *t1* 1862| *t2* *t3* *t4* 1863|x 私は猫が大好き *cats* ✨🐈✨ 1864]] ) 1865 1866feed ( 'gg<c-v>Gxgg' ) 1867end ) 1868 1869describe ( '(syntax)' , function () 1870before_each ( function () 1871command ( [[syntax region X0 matchgroup=X1 start=/\*/ end=/\*/ concealends contains=X2]] ) 1872command ( [[syntax match X2 /cats/ conceal cchar=X contained]] ) 1873command ( [[syntax match X3 /\n\@<=x/ conceal cchar=>]] ) 1874end ) 1875test_mouse_click_conceal () 1876end ) 1877 1878describe ( '(matchadd())' , function () 1879before_each ( function () 1880fn . matchadd ( 'Conceal' , [[\*]] ) 1881fn . matchadd ( 'Conceal' , [[cats]] , 10 , - 1 , { conceal ='X' } ) 1882fn . matchadd ( 'Conceal' , [[\n\@<=x]] , 10 , - 1 , { conceal ='>' } ) 1883end ) 1884test_mouse_click_conceal () 1885end ) 1886 1887describe ( '(extmarks)' , function () 1888before_each ( function () 1889local ns =api . nvim_create_namespace ( 'conceal' ) 1890api . nvim_buf_set_extmark ( 0 , ns , 0 , 11 , { end_col =12 , conceal ='' } ) 1891api . nvim_buf_set_extmark ( 0 , ns , 0 , 14 , { end_col =15 , conceal ='' } ) 1892api . nvim_buf_set_extmark ( 0 , ns , 1 , 5 , { end_col =6 , conceal ='' } ) 1893api . nvim_buf_set_extmark ( 0 , ns , 1 , 8 , { end_col =9 , conceal ='' } ) 1894api . nvim_buf_set_extmark ( 0 , ns , 1 , 10 , { end_col =11 , conceal ='' } ) 1895api . nvim_buf_set_extmark ( 0 , ns , 1 , 13 , { end_col =14 , conceal ='' } ) 1896api . nvim_buf_set_extmark ( 0 , ns , 1 , 15 , { end_col =16 , conceal ='' } ) 1897api . nvim_buf_set_extmark ( 0 , ns , 1 , 18 , { end_col =19 , conceal ='' } ) 1898api . nvim_buf_set_extmark ( 0 , ns , 2 , 24 , { end_col =25 , conceal ='' } ) 1899api . nvim_buf_set_extmark ( 0 , ns , 2 , 29 , { end_col =30 , conceal ='' } ) 1900api . nvim_buf_set_extmark ( 0 , ns , 2 , 25 , { end_col =29 , conceal ='X' } ) 1901api . nvim_buf_set_extmark ( 0 , ns , 2 , 0 , { end_col =1 , conceal ='>' } ) 1902end ) 1903test_mouse_click_conceal () 1904end ) 1905end ) 1906 1907it ( 'virtual text does not change cursor placement on concealed line' , function () 1908command ( '%delete' ) 1909insert ( 'aaaaaaaaaa|hidden|bbbbbbbbbb|hidden|cccccccccc' ) 1910command ( 'syntax match test /|hidden|/ conceal cchar=X' ) 1911command ( 'set conceallevel=2 concealcursor=n virtualedit=all' ) 1912screen : expect ( { 1913any ={ 1914'aaaaaaaaaa{14:X}bbbbbbb ' , 1915'bbb{14:X}ccccccccc%^c ' , 1916} , 1917} ) 1918api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 22 ) 1919screen : expect ( { 1920any ={ 1921'aaaaaaaaaa{14:X}bbbbbb%^b ' , 1922'bbb{14:X}cccccccccc ' , 1923} , 1924} ) 1925api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 1 , 16 ) 1926screen : expect ( { 1927any ={ 1928'aaaaaaaaaa{14:X}bbbbbbb ' , 1929'bbb{14:X}cccccccccc %^ ' , 1930} , 1931} ) 1932 1933api . nvim_buf_set_extmark ( 0 , api . nvim_create_namespace ( '' ), 0 , 0 , { 1934virt_text ={ { '?' , 'ErrorMsg' } } , 1935virt_text_pos ='right_align' , 1936virt_text_repeat_linebreak =true , 1937} ) 1938screen : expect ( { 1939any ={ 1940'aaaaaaaaaa{14:X}bbbbbbb {9:%?}' , 1941'bbb{14:X}cccccccccc %^ {9:%?}' , 1942} , 1943} ) 1944api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 22 ) 1945screen : expect ( { 1946any ={ 1947'aaaaaaaaaa{14:X}bbbbbb%^b {9:%?}' , 1948'bbb{14:X}cccccccccc {9:%?}' , 1949} , 1950} ) 1951api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 1 , 16 ) 1952screen : expect ( { 1953any ={ 1954'aaaaaaaaaa{14:X}bbbbbbb {9:%?}' , 1955'bbb{14:X}cccccccccc %^ {9:%?}' , 1956} , 1957} ) 1958end ) 1959 1960it ( "mouse click on window separator in statusline doesn't crash" , function () 1961api . nvim_set_option_value ( 'winwidth' , 1 , {} ) 1962api . nvim_set_option_value ( 'statusline' , '%f' , {} ) 1963 1964command ( 'vsplit' ) 1965command ( 'redraw' ) 1966 1967local lines =api . nvim_get_option_value ( 'lines' , {} ) 1968local columns =api . nvim_get_option_value ( 'columns' , {} ) 1969 1970api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , lines - 1 , math . floor ( columns / 2 )) 1971command ( 'redraw' ) 1972end ) 1973 1974it ( 'getmousepos() works correctly' , function () 1975local winwidth =api . nvim_get_option_value ( 'winwidth' , {} ) 1976-- Set winwidth=1 so that window sizes don't change. 1977api . nvim_set_option_value ( 'winwidth' , 1 , {} ) 1978command ( 'tabedit' ) 1979local tabpage =api . nvim_get_current_tabpage () 1980insert ( 'hello' ) 1981command ( 'vsplit' ) 1982local opts ={ 1983relative ='editor' , 1984width =12 , 1985height =1 , 1986col =8 , 1987row =1 , 1988anchor ='NW' , 1989style ='minimal' , 1990border ='single' , 1991focusable =1 , 1992} 1993local float =api . nvim_open_win ( api . nvim_get_current_buf (), false , opts ) 1994command ( 'redraw' ) 1995local lines =api . nvim_get_option_value ( 'lines' , {} ) 1996local columns =api . nvim_get_option_value ( 'columns' , {} ) 1997 1998-- Test that screenrow and screencol are set properly for all positions. 1999for row =0 , lines - 1 do 2000for col =0 , columns - 1 do 2001-- Skip the X button that would close the tab. 2002if row ~= 0 or col ~= columns - 1 then 2003api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , row , col ) 2004api . nvim_set_current_tabpage ( tabpage ) 2005local mousepos =fn . getmousepos () 2006eq ( row + 1 , mousepos . screenrow ) 2007eq ( col + 1 , mousepos . screencol ) 2008-- All other values should be 0 when clicking on the command line. 2009if row == lines - 1 then 2010eq ( 0 , mousepos . winid ) 2011eq ( 0 , mousepos . winrow ) 2012eq ( 0 , mousepos . wincol ) 2013eq ( 0 , mousepos . line ) 2014eq ( 0 , mousepos . column ) 2015eq ( 0 , mousepos . coladd ) 2016end 2017end 2018end 2019end 2020 2021-- Test that mouse position values are properly set for the floating window 2022-- with a border. 1 is added to the height and width to account for the 2023-- border. 2024for win_row =0 , opts . height + 1 do 2025for win_col =0 , opts . width + 1 do 2026local row =win_row + opts . row 2027local col =win_col + opts . col 2028api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , row , col ) 2029local mousepos =fn . getmousepos () 2030eq ( float , mousepos . winid ) 2031eq ( win_row + 1 , mousepos . winrow ) 2032eq ( win_col + 1 , mousepos . wincol ) 2033local line =0 2034local column =0 2035local coladd =0 2036if 2037win_row > 0 2038and win_row < opts . height + 1 2039and win_col > 0 2040and win_col < opts . width + 1 2041then 2042-- Because of border, win_row and win_col don't need to be 2043-- incremented by 1. 2044line =math . min ( win_row , fn . line ( '$' )) 2045column =math . min ( win_col , # fn . getline ( line ) + 1 ) 2046coladd =win_col - column 2047end 2048eq ( line , mousepos . line ) 2049eq ( column , mousepos . column ) 2050eq ( coladd , mousepos . coladd ) 2051end 2052end 2053 2054-- Test that mouse position values are properly set for the floating 2055-- window, after removing the border. 2056opts . border ='none' 2057api . nvim_win_set_config ( float , opts ) 2058command ( 'redraw' ) 2059for win_row =0 , opts . height - 1 do 2060for win_col =0 , opts . width - 1 do 2061local row =win_row + opts . row 2062local col =win_col + opts . col 2063api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , row , col ) 2064local mousepos =fn . getmousepos () 2065eq ( float , mousepos . winid ) 2066eq ( win_row + 1 , mousepos . winrow ) 2067eq ( win_col + 1 , mousepos . wincol ) 2068local line =math . min ( win_row + 1 , fn . line ( '$' )) 2069local column =math . min ( win_col + 1 , # fn . getline ( line ) + 1 ) 2070local coladd =win_col + 1 - column 2071eq ( line , mousepos . line ) 2072eq ( column , mousepos . column ) 2073eq ( coladd , mousepos . coladd ) 2074end 2075end 2076 2077-- Test that mouse position values are properly set for ordinary windows. 2078-- Set the float to be unfocusable instead of closing, to additionally test 2079-- that getmousepos() does not consider unfocusable floats. (see discussion 2080-- in PR #14937 for details). 2081opts . focusable =false 2082api . nvim_win_set_config ( float , opts ) 2083command ( 'redraw' ) 2084for nr =1 , 2 do 2085for win_row =0 , fn . winheight ( nr ) - 1 do 2086for win_col =0 , fn . winwidth ( nr ) - 1 do 2087local row =win_row + fn . win_screenpos ( nr )[ 1 ] - 1 2088local col =win_col + fn . win_screenpos ( nr )[ 2 ] - 1 2089api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , row , col ) 2090local mousepos =fn . getmousepos () 2091eq ( fn . win_getid ( nr ), mousepos . winid ) 2092eq ( win_row + 1 , mousepos . winrow ) 2093eq ( win_col + 1 , mousepos . wincol ) 2094local line =math . min ( win_row + 1 , fn . line ( '$' )) 2095local column =math . min ( win_col + 1 , # fn . getline ( line ) + 1 ) 2096local coladd =win_col + 1 - column 2097eq ( line , mousepos . line ) 2098eq ( column , mousepos . column ) 2099eq ( coladd , mousepos . coladd ) 2100end 2101end 2102end 2103 2104-- Restore state and release mouse. 2105command ( 'tabclose!' ) 2106api . nvim_set_option_value ( 'winwidth' , winwidth , {} ) 2107api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 0 , 0 ) 2108end ) 2109 2110it ( 'scroll keys are not translated into multiclicks and can be mapped #6211 #6989' , function () 2111api . nvim_set_var ( 'mouse_up' , 0 ) 2112api . nvim_set_var ( 'mouse_up2' , 0 ) 2113command ( 'nnoremap <ScrollWheelUp> <Cmd>let g:mouse_up += 1<CR>' ) 2114command ( 'nnoremap <2-ScrollWheelUp> <Cmd>let g:mouse_up2 += 1<CR>' ) 2115feed ( '<ScrollWheelUp><0,0>' ) 2116feed ( '<ScrollWheelUp><0,0>' ) 2117api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 0 , 0 ) 2118api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 0 , 0 ) 2119eq ( 4 , api . nvim_get_var ( 'mouse_up' )) 2120eq ( 0 , api . nvim_get_var ( 'mouse_up2' )) 2121end ) 2122 2123it ( '<MouseMove> to different locations can be mapped' , function () 2124api . nvim_set_var ( 'mouse_move' , 0 ) 2125api . nvim_set_var ( 'mouse_move2' , 0 ) 2126command ( 'nnoremap <MouseMove> <Cmd>let g:mouse_move += 1<CR>' ) 2127command ( 'nnoremap <2-MouseMove> <Cmd>let g:mouse_move2 += 1<CR>' ) 2128feed ( '<MouseMove><1,0>' ) 2129feed ( '<MouseMove><2,0>' ) 2130api . nvim_input_mouse ( 'move' , '' , '' , 0 , 0 , 3 ) 2131api . nvim_input_mouse ( 'move' , '' , '' , 0 , 0 , 4 ) 2132eq ( 4 , api . nvim_get_var ( 'mouse_move' )) 2133eq ( 0 , api . nvim_get_var ( 'mouse_move2' )) 2134end ) 2135 2136it ( '<MouseMove> to same location does not generate events #31103' , function () 2137api . nvim_set_var ( 'mouse_move' , 0 ) 2138api . nvim_set_var ( 'mouse_move2' , 0 ) 2139command ( 'nnoremap <MouseMove> <Cmd>let g:mouse_move += 1<CR>' ) 2140command ( 'nnoremap <2-MouseMove> <Cmd>let g:mouse_move2 += 1<CR>' ) 2141api . nvim_input_mouse ( 'move' , '' , '' , 0 , 0 , 3 ) 2142eq ( 1 , api . nvim_get_var ( 'mouse_move' )) 2143eq ( 0 , api . nvim_get_var ( 'mouse_move2' )) 2144feed ( '<MouseMove><3,0>' ) 2145feed ( '<MouseMove><3,0>' ) 2146api . nvim_input_mouse ( 'move' , '' , '' , 0 , 0 , 3 ) 2147api . nvim_input_mouse ( 'move' , '' , '' , 0 , 0 , 3 ) 2148eq ( 1 , api . nvim_get_var ( 'mouse_move' )) 2149eq ( 0 , api . nvim_get_var ( 'mouse_move2' )) 2150eq ( { mode ='n' , blocking =false } , api . nvim_get_mode ()) 2151feed ( '<MouseMove><3,0><Insert>' ) 2152eq ( 1 , api . nvim_get_var ( 'mouse_move' )) 2153eq ( 0 , api . nvim_get_var ( 'mouse_move2' )) 2154eq ( { mode ='i' , blocking =false } , api . nvim_get_mode ()) 2155end ) 2156 2157it ( 'dragging at same location does not generate events' , function () 2158api . nvim_set_var ( 'left_click' , 0 ) 2159api . nvim_set_var ( 'left_drag' , 0 ) 2160api . nvim_set_var ( 'left_release' , 0 ) 2161command ( 'nnoremap <LeftMouse> <Cmd>let g:left_click += 1<CR>' ) 2162command ( 'nnoremap <LeftDrag> <Cmd>let g:left_drag += 1<CR>' ) 2163command ( 'nnoremap <LeftRelease> <Cmd>let g:left_release += 1<CR>' ) 2164api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 3 ) 2165api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 0 , 3 ) 2166api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 0 , 3 ) 2167feed ( '<LeftDrag><3,0>' ) 2168feed ( '<LeftDrag><3,0>' ) 2169eq ( { 1 , 0 , 0 } , n . eval ( '[g:left_click, g:left_drag, g:left_release]' )) 2170api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 1 , 3 ) 2171api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 1 , 3 ) 2172feed ( '<LeftDrag><3,1>' ) 2173feed ( '<LeftDrag><3,1>' ) 2174eq ( { 1 , 1 , 0 } , n . eval ( '[g:left_click, g:left_drag, g:left_release]' )) 2175api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 2 , 3 ) 2176api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 2 , 3 ) 2177eq ( { 1 , 2 , 0 } , n . eval ( '[g:left_click, g:left_drag, g:left_release]' )) 2178feed ( '<LeftDrag><3,3>' ) 2179feed ( '<LeftDrag><3,3>' ) 2180eq ( { 1 , 3 , 0 } , n . eval ( '[g:left_click, g:left_drag, g:left_release]' )) 2181api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 3 , 3 ) 2182eq ( { 1 , 3 , 1 } , n . eval ( '[g:left_click, g:left_drag, g:left_release]' )) 2183end ) 2184 2185describe ( 'click event at different position resets multiclick count' , function () 2186before_each ( function () 2187api . nvim_set_var ( 'events' , {} ) 2188command ( 'nnoremap <LeftMouse> <Cmd>let g:events += [1]<CR>' ) 2189command ( 'nnoremap <2-LeftMouse> <Cmd>let g:events += [2]<CR>' ) 2190command ( 'nnoremap <3-LeftMouse> <Cmd>let g:events += [3]<CR>' ) 2191command ( 'nnoremap <4-LeftMouse> <Cmd>let g:events += [4]<CR>' ) 2192command ( 'nnoremap <LeftDrag> <Cmd>let g:events += [-1]<CR>' ) 2193command ( 'nnoremap <2-LeftDrag> <Cmd>let g:events += [-2]<CR>' ) 2194command ( 'nnoremap <3-LeftDrag> <Cmd>let g:events += [-3]<CR>' ) 2195command ( 'nnoremap <4-LeftDrag> <Cmd>let g:events += [-4]<CR>' ) 2196api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 3 ) 2197api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 0 , 3 ) 2198api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 3 ) 2199end ) 2200 2201it ( 'with drag events in between' , function () 2202api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 1 , 3 ) 2203api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 1 , 3 ) 2204api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 1 , 3 ) 2205api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 2 , 3 ) 2206api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 3 , 3 ) 2207for _ =1 , 3 do 2208api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 3 , 3 ) 2209api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 3 , 3 ) 2210end 2211api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 4 , 3 ) 2212api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 4 , 3 ) 2213eq ( { 1 , 2 , - 2 , 1 , - 1 , - 1 , 1 , 2 , 3 , - 3 } , api . nvim_get_var ( 'events' )) 2214end ) 2215 2216it ( 'with move events in between' , function () 2217api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 0 , 3 ) 2218api . nvim_input_mouse ( 'move' , '' , '' , 0 , 1 , 3 ) 2219api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 1 , 3 ) 2220api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 1 , 3 ) 2221api . nvim_input_mouse ( 'move' , '' , '' , 0 , 2 , 3 ) 2222for _ =1 , 3 do 2223api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 2 , 3 ) 2224api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 2 , 3 ) 2225end 2226api . nvim_input_mouse ( 'move' , '' , '' , 0 , 3 , 3 ) 2227for _ =1 , 4 do 2228api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 3 , 3 ) 2229api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 3 , 3 ) 2230end 2231eq ( { 1 , 2 , 1 , 1 , 2 , 3 , 1 , 2 , 3 , 4 } , api . nvim_get_var ( 'events' )) 2232end ) 2233end ) 2234 2235it ( 'feeding <MouseMove> in Normal mode does not use uninitialized memory #19480' , function () 2236feed ( '<MouseMove>' ) 2237n . poke_eventloop () 2238n . assert_alive () 2239end ) 2240 2241it ( 'mousemodel=popup_setpos' , function () 2242screen : try_resize ( 80 , 24 ) 2243exec ( [[ 22445new 2245call setline(1, ['the dish ran away with the spoon', 2246\ 'the cow jumped over the moon' ]) 2247 2248set mouse=a mousemodel=popup_setpos 2249 2250aunmenu PopUp 2251nmenu PopUp.foo :let g:menustr = 'foo'<CR> 2252nmenu PopUp.bar :let g:menustr = 'bar'<CR> 2253nmenu PopUp.baz :let g:menustr = 'baz'<CR> 2254vmenu PopUp.foo y:<C-U>let g:menustr = 'foo'<CR> 2255vmenu PopUp.bar y:<C-U>let g:menustr = 'bar'<CR> 2256vmenu PopUp.baz y:<C-U>let g:menustr = 'baz'<CR> 2257]] ) 2258 2259api . nvim_win_set_cursor ( 0 , { 1 , 0 } ) 2260api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 0 , 4 ) 2261api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 0 , 4 ) 2262feed ( '<Down><Down><CR>' ) 2263eq ( 'bar' , api . nvim_get_var ( 'menustr' )) 2264eq ( { 1 , 4 } , api . nvim_win_get_cursor ( 0 )) 2265 2266-- Test for right click in visual mode inside the selection 2267fn . setreg ( '"' , '' ) 2268api . nvim_win_set_cursor ( 0 , { 1 , 9 } ) 2269feed ( 'vee' ) 2270api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 0 , 11 ) 2271api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 0 , 11 ) 2272feed ( '<Down><CR>' ) 2273eq ( { 1 , 9 } , api . nvim_win_get_cursor ( 0 )) 2274eq ( 'ran away' , fn . getreg ( '"' )) 2275 2276-- Test for right click in visual mode right before the selection 2277fn . setreg ( '"' , '' ) 2278api . nvim_win_set_cursor ( 0 , { 1 , 9 } ) 2279feed ( 'vee' ) 2280api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 0 , 8 ) 2281api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 0 , 8 ) 2282feed ( '<Down><CR>' ) 2283eq ( { 1 , 8 } , api . nvim_win_get_cursor ( 0 )) 2284eq ( '' , fn . getreg ( '"' )) 2285 2286-- Test for right click in visual mode right after the selection 2287fn . setreg ( '"' , '' ) 2288api . nvim_win_set_cursor ( 0 , { 1 , 9 } ) 2289feed ( 'vee' ) 2290api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 0 , 17 ) 2291api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 0 , 17 ) 2292feed ( '<Down><CR>' ) 2293eq ( { 1 , 17 } , api . nvim_win_get_cursor ( 0 )) 2294eq ( '' , fn . getreg ( '"' )) 2295 2296-- Test for right click in block-wise visual mode inside the selection 2297fn . setreg ( '"' , '' ) 2298api . nvim_win_set_cursor ( 0 , { 1 , 15 } ) 2299feed ( '<C-V>j3l' ) 2300api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 1 , 16 ) 2301api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 1 , 16 ) 2302feed ( '<Down><CR>' ) 2303eq ( { 1 , 15 } , api . nvim_win_get_cursor ( 0 )) 2304eq ( '\0224' , fn . getregtype ( '"' )) 2305 2306-- Test for right click in block-wise visual mode outside the selection 2307fn . setreg ( '"' , '' ) 2308api . nvim_win_set_cursor ( 0 , { 1 , 15 } ) 2309feed ( '<C-V>j3l' ) 2310api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 1 , 1 ) 2311api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 1 , 1 ) 2312feed ( '<Down><CR>' ) 2313eq ( { 2 , 1 } , api . nvim_win_get_cursor ( 0 )) 2314eq ( 'v' , fn . getregtype ( '"' )) 2315eq ( '' , fn . getreg ( '"' )) 2316 2317-- Test for right click in line-wise visual mode inside the selection 2318fn . setreg ( '"' , '' ) 2319api . nvim_win_set_cursor ( 0 , { 1 , 15 } ) 2320feed ( 'V' ) 2321api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 0 , 9 ) 2322api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 0 , 9 ) 2323feed ( '<Down><CR>' ) 2324eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) -- After yanking, the cursor goes to 1,1 2325eq ( 'V' , fn . getregtype ( '"' )) 2326eq ( 1 , # fn . getreg ( '"' , 1 , true )) 2327 2328-- Test for right click in multi-line line-wise visual mode inside the selection 2329fn . setreg ( '"' , '' ) 2330api . nvim_win_set_cursor ( 0 , { 1 , 15 } ) 2331feed ( 'Vj' ) 2332api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 1 , 19 ) 2333api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 1 , 19 ) 2334feed ( '<Down><CR>' ) 2335eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) -- After yanking, the cursor goes to 1,1 2336eq ( 'V' , fn . getregtype ( '"' )) 2337eq ( 2 , # fn . getreg ( '"' , 1 , true )) 2338 2339-- Test for right click in line-wise visual mode outside the selection 2340fn . setreg ( '"' , '' ) 2341api . nvim_win_set_cursor ( 0 , { 1 , 15 } ) 2342feed ( 'V' ) 2343api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 1 , 9 ) 2344api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 1 , 9 ) 2345feed ( '<Down><CR>' ) 2346eq ( { 2 , 9 } , api . nvim_win_get_cursor ( 0 )) 2347eq ( '' , fn . getreg ( '"' )) 2348 2349-- Try clicking outside the window 2350fn . setreg ( '"' , '' ) 2351api . nvim_win_set_cursor ( 0 , { 2 , 1 } ) 2352feed ( 'vee' ) 2353api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 6 , 1 ) 2354api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 6 , 1 ) 2355feed ( '<Down><CR>' ) 2356eq ( 2 , fn . winnr ()) 2357eq ( '' , fn . getreg ( '"' )) 2358 2359-- Test for right click in visual mode inside the selection with vertical splits 2360command ( 'wincmd t' ) 2361command ( 'rightbelow vsplit' ) 2362fn . setreg ( '"' , '' ) 2363api . nvim_win_set_cursor ( 0 , { 1 , 9 } ) 2364feed ( 'vee' ) 2365api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 0 , 52 ) 2366api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 0 , 52 ) 2367feed ( '<Down><CR>' ) 2368eq ( { 1 , 9 } , api . nvim_win_get_cursor ( 0 )) 2369eq ( 'ran away' , fn . getreg ( '"' )) 2370 2371-- Test for right click inside visual selection at bottom of window with winbar 2372command ( 'setlocal winbar=WINBAR' ) 2373feed ( '2yyP' ) 2374fn . setreg ( '"' , '' ) 2375feed ( 'G$vbb' ) 2376api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 4 , 61 ) 2377api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 4 , 61 ) 2378feed ( '<Down><CR>' ) 2379eq ( { 4 , 20 } , api . nvim_win_get_cursor ( 0 )) 2380eq ( 'the moon' , fn . getreg ( '"' )) 2381 2382-- Try clicking in the cmdline 2383api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 23 , 0 ) 2384api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 23 , 0 ) 2385feed ( '<Down><Down><Down><CR>' ) 2386eq ( 'baz' , api . nvim_get_var ( 'menustr' )) 2387 2388-- Try clicking in horizontal separator with global statusline 2389command ( 'set laststatus=3' ) 2390api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 5 , 0 ) 2391api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 5 , 0 ) 2392feed ( '<Down><CR>' ) 2393eq ( 'foo' , api . nvim_get_var ( 'menustr' )) 2394 2395-- Try clicking in the cmdline with global statusline 2396api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 23 , 0 ) 2397api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 23 , 0 ) 2398feed ( '<Down><Down><CR>' ) 2399eq ( 'bar' , api . nvim_get_var ( 'menustr' )) 2400end ) 2401 2402it ( 'below a concealed line #33450' , function () 2403api . nvim_set_option_value ( 'conceallevel' , 2 , {} ) 2404api . nvim_buf_set_extmark ( 0 , api . nvim_create_namespace ( '' ), 1 , 0 , { conceal_lines ='' } ) 2405api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 1 , 0 ) 2406api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 1 , 0 ) 2407eq ( 3 , fn . line ( '.' )) 2408-- No error when clicking below last line that is concealed. 2409screen : try_resize ( 80 , 10 ) -- Prevent hit-enter 2410api . nvim_set_option_value ( 'cmdheight' , 3 , {} ) 2411local count =api . nvim_buf_line_count ( 0 ) 2412api . nvim_buf_set_extmark ( 0 , 1 , count - 1 , 0 , { conceal_lines ='' } ) 2413api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , count , 0 ) 2414eq ( '' , api . nvim_get_vvar ( 'errmsg' )) 2415end ) 2416 2417it ( 'on virtual lines (above/below)' , function () 2418screen : try_resize ( screen . _width , 12 ) 2419local ns =api . nvim_create_namespace ( '' ) 2420api . nvim_buf_set_extmark ( 0 , ns , 1 , 0 , { virt_lines ={ { { 'virt_line below' , '' } } } } ) 2421api . nvim_buf_set_extmark ( 0 , ns , 1 , 0 , { virt_lines ={ { { 'virt_line below' , '' } } } } ) 2422local virt_above ={ virt_lines_above =true , virt_lines ={ { { 'virt_line above' , '' } } } } 2423api . nvim_buf_set_extmark ( 0 , ns , 2 , 0 , virt_above ) 2424api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 2 , 0 ) 2425api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 2 , 0 ) 2426eq ( 2 , fn . line ( '.' )) 2427api . nvim_win_set_cursor ( 0 , { 1 , 0 } ) 2428api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 3 , 0 ) 2429api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 3 , 0 ) 2430eq ( 2 , fn . line ( '.' )) 2431api . nvim_win_set_cursor ( 0 , { 1 , 0 } ) 2432api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 4 , 0 ) 2433api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 4 , 0 ) 2434eq ( 3 , fn . line ( '.' )) 2435feed ( 'gg2<C-E>' ) 2436api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 0 ) 2437api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 0 , 0 ) 2438eq ( 2 , fn . line ( '.' )) 2439feed ( 'gg2<C-E>' ) 2440api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 1 , 0 ) 2441api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 1 , 0 ) 2442eq ( 2 , fn . line ( '.' )) 2443feed ( 'gg2<C-E>' ) 2444api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 2 , 0 ) 2445api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 2 , 0 ) 2446eq ( 3 , fn . line ( '.' )) 2447feed ( 'gg3<C-E>' ) 2448api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 0 ) 2449api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 0 , 0 ) 2450eq ( 2 , fn . line ( '.' )) 2451feed ( 'gg3<C-E>' ) 2452api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 1 , 0 ) 2453api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 1 , 0 ) 2454eq ( 3 , fn . line ( '.' )) 2455feed ( 'gg' ) 2456command ( 'call setline(3, ["3"->repeat(&columns + 1), "4"])' ) 2457api . nvim_buf_set_extmark ( 0 , ns , 2 , 0 , { virt_lines ={ { { 'virt_line below' , '' } } } } ) 2458api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 7 , 0 ) 2459api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 7 , 0 ) 2460eq ( 3 , fn . line ( '.' )) 2461end ) 2462end 2463 2464describe ( 'with ext_multigrid' , function () 2465with_ext_multigrid ( true ) 2466end ) 2467 2468describe ( 'without ext_multigrid' , function () 2469with_ext_multigrid ( false ) 2470end ) 2471end )