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 request =n . request 7local eq =t . eq 8local ok =t . ok 9local pcall_err =t . pcall_err 10local insert =n . insert 11local feed =n . feed 12local clear =n . clear 13local command =n . command 14local exec =n . exec 15local exec_lua =n . exec_lua 16local api =n . api 17local fn =n . fn 18local assert_alive =n . assert_alive 19 20local function expect ( contents ) 21return eq ( contents , n . curbuf_contents ()) 22end 23 24local function set_extmark ( ns_id , id , line , col , opts ) 25if opts == nil then 26opts ={} 27end 28if id ~= nil and id ~= 0 then 29opts . id =id 30end 31return api . nvim_buf_set_extmark ( 0 , ns_id , line , col , opts ) 32end 33 34local function get_extmarks ( ns_id , start , end_ , opts ) 35if opts == nil then 36opts ={} 37end 38return api . nvim_buf_get_extmarks ( 0 , ns_id , start , end_ , opts ) 39end 40 41local function get_extmark_by_id ( ns_id , id , opts ) 42if opts == nil then 43opts ={} 44end 45return api . nvim_buf_get_extmark_by_id ( 0 , ns_id , id , opts ) 46end 47 48local function check_undo_redo ( ns , mark , sr , sc , er , ec ) --s = start, e = end 49local rv =get_extmark_by_id ( ns , mark ) 50eq ( { er , ec } , rv ) 51feed ( 'u' ) 52rv =get_extmark_by_id ( ns , mark ) 53eq ( { sr , sc } , rv ) 54feed ( '<c-r>' ) 55rv =get_extmark_by_id ( ns , mark ) 56eq ( { er , ec } , rv ) 57end 58 59local function batch_set ( ns_id , positions ) 60local ids ={} 61for _ , pos in ipairs ( positions ) do 62table . insert ( ids , set_extmark ( ns_id , 0 , pos [ 1 ], pos [ 2 ])) 63end 64return ids 65end 66 67local function batch_check ( ns_id , ids , positions ) 68local actual , expected ={} , {} 69for i , id in ipairs ( ids ) do 70expected [ id ] =positions [ i ] 71end 72for _ , mark in pairs ( get_extmarks ( ns_id , 0 , - 1 , {} )) do 73actual [ mark [ 1 ]] ={ mark [ 2 ], mark [ 3 ] } 74end 75eq ( expected , actual ) 76end 77 78local function batch_check_undo_redo ( ns_id , ids , before , after ) 79batch_check ( ns_id , ids , after ) 80feed ( 'u' ) 81batch_check ( ns_id , ids , before ) 82feed ( '<c-r>' ) 83batch_check ( ns_id , ids , after ) 84end 85 86describe ( 'API/extmarks' , function () 87local screen 88local marks , positions , init_text , row , col 89local ns , ns2 ---@type integer, integer 90 91before_each ( function () 92-- Initialize some namespaces and insert 12345 into a buffer 93marks ={ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } 94positions ={ { 0 , 0 } , { 0 , 2 } , { 0 , 3 } } 95 96init_text ='12345' 97row =0 98col =2 99 100clear () 101 102insert ( init_text ) 103ns =request ( 'nvim_create_namespace' , 'my-fancy-plugin' ) 104ns2 =request ( 'nvim_create_namespace' , 'my-fancy-plugin2' ) 105end ) 106 107it ( 'validation' , function () 108eq ( 109"Invalid 'end_col': expected Integer, got Array" , 110pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { end_col ={} , end_row =1 } ) 111) 112eq ( 113"Invalid 'end_row': expected Integer, got Array" , 114pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { end_col =1 , end_row ={} } ) 115) 116eq ( 117"Invalid 'virt_text_pos': expected String, got Integer" , 118pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { virt_text_pos =0 } ) 119) 120eq ( 121"Invalid 'virt_text_pos': 'foo'" , 122pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { virt_text_pos ='foo' } ) 123) 124eq ( 125"Invalid 'hl_mode': expected String, got Integer" , 126pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { hl_mode =0 } ) 127) 128eq ( "Invalid 'hl_mode': 'foo'" , pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { hl_mode ='foo' } )) 129eq ( 130"Invalid 'virt_lines_overflow': 'foo'" , 131pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { virt_lines_overflow ='foo' } ) 132) 133eq ( 134"Invalid 'id': expected Integer, got Array" , 135pcall_err ( set_extmark , ns , {} , 0 , 0 , { end_col =1 , end_row =1 } ) 136) 137eq ( 138'Invalid mark position: expected 2 Integer items' , 139pcall_err ( get_extmarks , ns , {} , { - 1 , - 1 } ) 140) 141eq ( 142'Invalid mark position: expected mark id Integer or 2-item Array' , 143pcall_err ( get_extmarks , ns , true , { - 1 , - 1 } ) 144) 145-- No memory leak with virt_text, virt_lines, sign_text 146eq ( 147"Invalid 'right_gravity': expected boolean" , 148pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { 149virt_text ={ { 'foo' , 'Normal' } } , 150virt_lines ={ { { 'bar' , 'Normal' } } } , 151sign_text ='a' , 152right_gravity ='baz' , 153} ) 154) 155end ) 156 157it ( 'can end extranges past final newline using end_col=0' , function () 158set_extmark ( ns , marks [ 1 ], 0 , 0 , { 159end_col =0 , 160end_row =1 , 161} ) 162eq ( 163"Invalid 'end_col': out of range" , 164pcall_err ( set_extmark , ns , marks [ 2 ], 0 , 0 , { end_col =1 , end_row =1 } ) 165) 166end ) 167 168it ( 'can end extranges past final newline when strict=false' , function () 169local id =set_extmark ( ns , marks [ 1 ], 0 , 0 , { 170end_col =1 , 171end_row =1 , 172strict =false , 173} ) 174ok ( id > 0 , 'id > 0' , id ) 175end ) 176 177it ( 'can end extranges past final column when strict=false' , function () 178local id =set_extmark ( ns , marks [ 1 ], 0 , 0 , { 179end_col =6 , 180end_row =0 , 181strict =false , 182} ) 183ok ( id > 0 , 'id > 0' , id ) 184end ) 185 186it ( 'end_col=-1 means "end of line" when strict=false' , function () 187local function _test ( strict ) 188return set_extmark ( ns , marks [ 1 ], 0 , 0 , { 189end_col =- 1 , 190end_row =0 , 191strict =strict , 192} ) 193end 194 195-- strict=false 196local id =_test ( false ) 197ok ( id > 0 , 'id > 0' , id ) 198 199-- strict=true 200eq ( "Invalid 'end_col': out of range" , pcall_err ( _test , true )) 201end ) 202 203it ( 'adds, updates and deletes marks' , function () 204local rv =set_extmark ( ns , marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ]) 205eq ( marks [ 1 ], rv ) 206rv =get_extmark_by_id ( ns , marks [ 1 ]) 207eq ( { positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } , rv ) 208-- Test adding a second mark on same row works 209rv =set_extmark ( ns , marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ]) 210eq ( marks [ 2 ], rv ) 211 212-- Test an update, (same pos) 213rv =set_extmark ( ns , marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ]) 214eq ( marks [ 1 ], rv ) 215rv =get_extmark_by_id ( ns , marks [ 2 ]) 216eq ( { positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } , rv ) 217-- Test an update, (new pos) 218row =positions [ 1 ][ 1 ] 219col =positions [ 1 ][ 2 ] + 1 220rv =set_extmark ( ns , marks [ 1 ], row , col ) 221eq ( marks [ 1 ], rv ) 222rv =get_extmark_by_id ( ns , marks [ 1 ]) 223eq ( { row , col } , rv ) 224 225-- remove the test marks 226eq ( true , api . nvim_buf_del_extmark ( 0 , ns , marks [ 1 ])) 227eq ( false , api . nvim_buf_del_extmark ( 0 , ns , marks [ 1 ])) 228eq ( true , api . nvim_buf_del_extmark ( 0 , ns , marks [ 2 ])) 229eq ( false , api . nvim_buf_del_extmark ( 0 , ns , marks [ 3 ])) 230eq ( false , api . nvim_buf_del_extmark ( 0 , ns , 1000 )) 231end ) 232 233it ( 'can clear a specific namespace range' , function () 234set_extmark ( ns , 1 , 0 , 1 ) 235set_extmark ( ns2 , 1 , 0 , 1 ) 236-- force a new undo buffer 237feed ( 'o<esc>' ) 238api . nvim_buf_clear_namespace ( 0 , ns2 , 0 , - 1 ) 239eq ( { { 1 , 0 , 1 } } , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 240eq ( {} , get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } )) 241feed ( 'u' ) 242eq ( { { 1 , 0 , 1 } } , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 243eq ( {} , get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } )) 244feed ( '<c-r>' ) 245eq ( { { 1 , 0 , 1 } } , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 246eq ( {} , get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } )) 247end ) 248 249it ( 'can clear a namespace range using 0,-1' , function () 250set_extmark ( ns , 1 , 0 , 1 ) 251set_extmark ( ns2 , 1 , 0 , 1 ) 252-- force a new undo buffer 253feed ( 'o<esc>' ) 254api . nvim_buf_clear_namespace ( 0 , - 1 , 0 , - 1 ) 255eq ( {} , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 256eq ( {} , get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } )) 257feed ( 'u' ) 258eq ( {} , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 259eq ( {} , get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } )) 260feed ( '<c-r>' ) 261eq ( {} , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 262eq ( {} , get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } )) 263end ) 264 265it ( 'can undo with extmarks (#25147)' , function () 266feed ( 'itest<esc>' ) 267set_extmark ( ns , 1 , 0 , 0 ) 268set_extmark ( ns , 2 , 1 , 0 ) 269eq ( { { 1 , 0 , 0 } , { 2 , 1 , 0 } } , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 270feed ( 'dd' ) 271eq ( { { 1 , 1 , 0 } , { 2 , 1 , 0 } } , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 272api . nvim_buf_clear_namespace ( 0 , ns , 0 , - 1 ) 273eq ( {} , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 274set_extmark ( ns , 1 , 0 , 0 , { right_gravity =false } ) 275set_extmark ( ns , 2 , 1 , 0 , { right_gravity =false } ) 276eq ( { { 1 , 0 , 0 } , { 2 , 1 , 0 } } , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 277feed ( 'u' ) 278eq ( { { 1 , 0 , 0 } , { 2 , 0 , 0 } } , get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } )) 279api . nvim_buf_clear_namespace ( 0 , ns , 0 , - 1 ) 280end ) 281 282it ( 'querying for information and ranges' , function () 283--marks = {1, 2, 3} 284--positions = {{0, 0,}, {0, 2}, {0, 3}} 285-- add some more marks 286for i , m in ipairs ( marks ) do 287if positions [ i ] ~= nil then 288local rv =set_extmark ( ns , m , positions [ i ][ 1 ], positions [ i ][ 2 ]) 289eq ( m , rv ) 290end 291end 292 293-- {0, 0} and {-1, -1} work as extreme values 294eq ( { { 1 , 0 , 0 } } , get_extmarks ( ns , { 0 , 0 } , { 0 , 0 } )) 295eq ( {} , get_extmarks ( ns , { - 1 , - 1 } , { - 1 , - 1 } )) 296local rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } ) 297for i , m in ipairs ( marks ) do 298if positions [ i ] ~= nil then 299eq ( { m , positions [ i ][ 1 ], positions [ i ][ 2 ] } , rv [ i ]) 300end 301end 302 303-- 0 and -1 works as short hand extreme values 304eq ( { { 1 , 0 , 0 } } , get_extmarks ( ns , 0 , 0 )) 305eq ( {} , get_extmarks ( ns , - 1 , - 1 )) 306rv =get_extmarks ( ns , 0 , - 1 ) 307for i , m in ipairs ( marks ) do 308if positions [ i ] ~= nil then 309eq ( { m , positions [ i ][ 1 ], positions [ i ][ 2 ] } , rv [ i ]) 310end 311end 312 313-- next with mark id 314rv =get_extmarks ( ns , marks [ 1 ], { - 1 , - 1 } , { limit =1 } ) 315eq ( { { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } } , rv ) 316rv =get_extmarks ( ns , marks [ 2 ], { - 1 , - 1 } , { limit =1 } ) 317eq ( { { marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } } , rv ) 318-- next with positional when mark exists at position 319rv =get_extmarks ( ns , positions [ 1 ], { - 1 , - 1 } , { limit =1 } ) 320eq ( { { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } } , rv ) 321-- next with positional index (no mark at position) 322rv =get_extmarks ( ns , { positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] + 1 } , { - 1 , - 1 } , { limit =1 } ) 323eq ( { { marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } } , rv ) 324-- next with Extremity index 325rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } , { limit =1 } ) 326eq ( { { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } } , rv ) 327 328-- nextrange with mark id 329rv =get_extmarks ( ns , marks [ 1 ], marks [ 3 ]) 330eq ( { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } , rv [ 1 ]) 331eq ( { marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } , rv [ 2 ]) 332-- nextrange with `limit` 333rv =get_extmarks ( ns , marks [ 1 ], marks [ 3 ], { limit =2 } ) 334eq ( 2 , # rv ) 335-- nextrange with positional when mark exists at position 336rv =get_extmarks ( ns , positions [ 1 ], positions [ 3 ]) 337eq ( { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } , rv [ 1 ]) 338eq ( { marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } , rv [ 2 ]) 339rv =get_extmarks ( ns , positions [ 2 ], positions [ 3 ]) 340eq ( 2 , # rv ) 341-- nextrange with positional index (no mark at position) 342local lower ={ positions [ 1 ][ 1 ], positions [ 2 ][ 2 ] - 1 } 343local upper ={ positions [ 2 ][ 1 ], positions [ 3 ][ 2 ] - 1 } 344rv =get_extmarks ( ns , lower , upper ) 345eq ( { { marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } } , rv ) 346lower ={ positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] + 1 } 347upper ={ positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] + 2 } 348rv =get_extmarks ( ns , lower , upper ) 349eq ( {} , rv ) 350-- nextrange with extremity index 351lower ={ positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] + 1 } 352upper ={ - 1 , - 1 } 353rv =get_extmarks ( ns , lower , upper ) 354eq ( { { marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] } } , rv ) 355 356-- reverse with mark id 357rv =get_extmarks ( ns , marks [ 3 ], { 0 , 0 } , { limit =1 } ) 358eq ( { { marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] } } , rv ) 359rv =get_extmarks ( ns , marks [ 2 ], { 0 , 0 } , { limit =1 } ) 360eq ( { { marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } } , rv ) 361-- reverse with positional when mark exists at position 362rv =get_extmarks ( ns , positions [ 3 ], { 0 , 0 } , { limit =1 } ) 363eq ( { { marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] } } , rv ) 364-- reverse with positional index (no mark at position) 365rv =get_extmarks ( ns , { positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] + 1 } , { 0 , 0 } , { limit =1 } ) 366eq ( { { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } } , rv ) 367-- reverse with Extremity index 368rv =get_extmarks ( ns , { - 1 , - 1 } , { 0 , 0 } , { limit =1 } ) 369eq ( { { marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] } } , rv ) 370 371-- reverse with mark id 372rv =get_extmarks ( ns , marks [ 3 ], marks [ 1 ]) 373eq ( { marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] } , rv [ 1 ]) 374eq ( { marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } , rv [ 2 ]) 375eq ( { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } , rv [ 3 ]) 376-- reverse with limit 377rv =get_extmarks ( ns , marks [ 3 ], marks [ 1 ], { limit =2 } ) 378eq ( 2 , # rv ) 379-- reverse with positional when mark exists at position 380rv =get_extmarks ( ns , positions [ 3 ], positions [ 1 ]) 381eq ( { 382{ marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] } , 383{ marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] } , 384{ marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } , 385} , rv ) 386rv =get_extmarks ( ns , positions [ 2 ], positions [ 1 ]) 387eq ( 2 , # rv ) 388-- reverse with positional index (no mark at position) 389lower ={ positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] + 1 } 390upper ={ positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] + 1 } 391rv =get_extmarks ( ns , upper , lower ) 392eq ( { { marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] } } , rv ) 393lower ={ positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] + 1 } 394upper ={ positions [ 3 ][ 1 ], positions [ 3 ][ 2 ] + 2 } 395rv =get_extmarks ( ns , upper , lower ) 396eq ( {} , rv ) 397-- reverse with extremity index 398lower ={ 0 , 0 } 399upper ={ positions [ 2 ][ 1 ], positions [ 2 ][ 2 ] - 1 } 400rv =get_extmarks ( ns , upper , lower ) 401eq ( { { marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ] } } , rv ) 402end ) 403 404it ( 'querying for information with limit' , function () 405-- add some more marks 406for i , m in ipairs ( marks ) do 407if positions [ i ] ~= nil then 408local rv =set_extmark ( ns , m , positions [ i ][ 1 ], positions [ i ][ 2 ]) 409eq ( m , rv ) 410end 411end 412 413local rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } , { limit =1 } ) 414eq ( 1 , # rv ) 415rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } , { limit =2 } ) 416eq ( 2 , # rv ) 417rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } , { limit =3 } ) 418eq ( 3 , # rv ) 419 420-- now in reverse 421rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } , { limit =1 } ) 422eq ( 1 , # rv ) 423rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } , { limit =2 } ) 424eq ( 2 , # rv ) 425rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } , { limit =3 } ) 426eq ( 3 , # rv ) 427end ) 428 429it ( 'get_marks works when mark col > upper col' , function () 430feed ( 'A<cr>12345<esc>' ) 431feed ( 'A<cr>12345<esc>' ) 432set_extmark ( ns , 10 , 0 , 2 ) -- this shouldn't be found 433set_extmark ( ns , 11 , 2 , 1 ) -- this shouldn't be found 434set_extmark ( ns , marks [ 1 ], 0 , 4 ) -- check col > our upper bound 435set_extmark ( ns , marks [ 2 ], 1 , 1 ) -- check col < lower bound 436set_extmark ( ns , marks [ 3 ], 2 , 0 ) -- check is inclusive 437eq ( 438{ { marks [ 1 ], 0 , 4 } , { marks [ 2 ], 1 , 1 } , { marks [ 3 ], 2 , 0 } } , 439get_extmarks ( ns , { 0 , 3 } , { 2 , 0 } ) 440) 441end ) 442 443it ( 'get_marks works in reverse when mark col < lower col' , function () 444feed ( 'A<cr>12345<esc>' ) 445feed ( 'A<cr>12345<esc>' ) 446set_extmark ( ns , 10 , 0 , 1 ) -- this shouldn't be found 447set_extmark ( ns , 11 , 2 , 4 ) -- this shouldn't be found 448set_extmark ( ns , marks [ 1 ], 2 , 1 ) -- check col < our lower bound 449set_extmark ( ns , marks [ 2 ], 1 , 4 ) -- check col > upper bound 450set_extmark ( ns , marks [ 3 ], 0 , 2 ) -- check is inclusive 451local rv =get_extmarks ( ns , { 2 , 3 } , { 0 , 2 } ) 452eq ( { { marks [ 1 ], 2 , 1 } , { marks [ 2 ], 1 , 4 } , { marks [ 3 ], 0 , 2 } } , rv ) 453-- doesn't include paired marks whose start pos > lower bound twice 454-- and returns mark overlapping start pos but not end pos 455local m1 =set_extmark ( ns , nil , 0 , 0 , { end_row =1 , end_col =4 } ) 456local m2 =set_extmark ( ns , nil , 0 , 0 , { end_row =1 , end_col =2 } ) 457local m3 =set_extmark ( ns , nil , 1 , 0 , { end_row =1 , end_col =4 } ) 458local m4 =set_extmark ( ns , nil , 1 , 2 , { end_row =1 , end_col =4 } ) 459rv =get_extmarks ( ns , { 1 , 3 } , { 1 , 2 } , { overlap =true } ) 460eq ( { { m4 , 1 , 2 } , { m3 , 1 , 0 } , { m2 , 0 , 0 } , { m1 , 0 , 0 } } , rv ) 461end ) 462 463it ( 'get_marks limit=0 returns nothing' , function () 464set_extmark ( ns , marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ]) 465local rv =get_extmarks ( ns , { - 1 , - 1 } , { - 1 , - 1 } , { limit =0 } ) 466eq ( {} , rv ) 467end ) 468 469it ( 'marks move with line insertations' , function () 470set_extmark ( ns , marks [ 1 ], 0 , 0 ) 471feed ( 'yyP' ) 472check_undo_redo ( ns , marks [ 1 ], 0 , 0 , 1 , 0 ) 473end ) 474 475it ( 'marks move with multiline insertations' , function () 476feed ( 'a<cr>22<cr>33<esc>' ) 477set_extmark ( ns , marks [ 1 ], 1 , 1 ) 478feed ( 'ggVGyP' ) 479check_undo_redo ( ns , marks [ 1 ], 1 , 1 , 4 , 1 ) 480end ) 481 482it ( 'marks move with line join' , function () 483-- do_join in ops.c 484feed ( 'a<cr>222<esc>' ) 485set_extmark ( ns , marks [ 1 ], 1 , 0 ) 486feed ( 'ggJ' ) 487check_undo_redo ( ns , marks [ 1 ], 1 , 0 , 0 , 6 ) 488end ) 489 490it ( 'join works when no marks are present' , function () 491screen =Screen . new ( 15 , 10 ) 492feed ( 'a<cr>1<esc>' ) 493feed ( 'kJ' ) 494-- This shouldn't seg fault 495screen : expect ( [[ 49612345^ 1 | 497{1:~ }|*8 498| 499]] ) 500end ) 501 502it ( 'marks move with multiline join' , function () 503-- do_join in ops.c 504feed ( 'a<cr>222<cr>333<cr>444<esc>' ) 505set_extmark ( ns , marks [ 1 ], 3 , 0 ) 506feed ( '2GVGJ' ) 507check_undo_redo ( ns , marks [ 1 ], 3 , 0 , 1 , 8 ) 508end ) 509 510it ( 'marks move with line deletes' , function () 511feed ( 'a<cr>222<cr>333<cr>444<esc>' ) 512set_extmark ( ns , marks [ 1 ], 2 , 1 ) 513feed ( 'ggjdd' ) 514check_undo_redo ( ns , marks [ 1 ], 2 , 1 , 1 , 1 ) 515end ) 516 517it ( 'marks move with multiline deletes' , function () 518feed ( 'a<cr>222<cr>333<cr>444<esc>' ) 519set_extmark ( ns , marks [ 1 ], 3 , 0 ) 520feed ( 'gg2dd' ) 521check_undo_redo ( ns , marks [ 1 ], 3 , 0 , 1 , 0 ) 522-- regression test, undoing multiline delete when mark is on row 1 523feed ( 'ugg3dd' ) 524check_undo_redo ( ns , marks [ 1 ], 3 , 0 , 0 , 0 ) 525end ) 526 527it ( 'marks move with open line' , function () 528-- open_line in change.c 529-- testing marks below are also moved 530feed ( 'yyP' ) 531set_extmark ( ns , marks [ 1 ], 0 , 4 ) 532set_extmark ( ns , marks [ 2 ], 1 , 4 ) 533feed ( '1G<s-o><esc>' ) 534check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 1 , 4 ) 535check_undo_redo ( ns , marks [ 2 ], 1 , 4 , 2 , 4 ) 536feed ( '2Go<esc>' ) 537check_undo_redo ( ns , marks [ 1 ], 1 , 4 , 1 , 4 ) 538check_undo_redo ( ns , marks [ 2 ], 2 , 4 , 3 , 4 ) 539end ) 540 541it ( 'marks move with char inserts' , function () 542-- insertchar in insert.c (the ins_str branch) 543screen =Screen . new ( 15 , 10 ) 544set_extmark ( ns , marks [ 1 ], 0 , 3 ) 545feed ( '0' ) 546insert ( 'abc' ) 547screen : expect ( [[ 548ab^c12345 | 549{1:~ }|*8 550| 551]] ) 552local rv =get_extmark_by_id ( ns , marks [ 1 ]) 553eq ( { 0 , 6 } , rv ) 554check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 6 ) 555end ) 556 557-- gravity right as definted in tk library 558it ( 'marks have gravity right' , function () 559-- insertchar in insert.c (the ins_str branch) 560set_extmark ( ns , marks [ 1 ], 0 , 2 ) 561feed ( '03l' ) 562insert ( 'X' ) 563check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 564 565-- check multibyte chars 566feed ( '03l<esc>' ) 567insert ( '~~' ) 568check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 569end ) 570 571it ( 'we can insert multibyte chars' , function () 572-- insertchar in insert.c 573feed ( 'a<cr>12345<esc>' ) 574set_extmark ( ns , marks [ 1 ], 1 , 2 ) 575-- Insert a fullwidth (two col) tilde, NICE 576feed ( '0i~<esc>' ) 577check_undo_redo ( ns , marks [ 1 ], 1 , 2 , 1 , 5 ) 578end ) 579 580it ( 'marks move with blockwise inserts' , function () 581-- op_insert in ops.c 582feed ( 'a<cr>12345<esc>' ) 583set_extmark ( ns , marks [ 1 ], 1 , 2 ) 584feed ( '0<c-v>lkI9<esc>' ) 585check_undo_redo ( ns , marks [ 1 ], 1 , 2 , 1 , 3 ) 586end ) 587 588it ( 'marks move with line splits (using enter)' , function () 589-- open_line in change.c 590-- testing marks below are also moved 591feed ( 'yyP' ) 592set_extmark ( ns , marks [ 1 ], 0 , 4 ) 593set_extmark ( ns , marks [ 2 ], 1 , 4 ) 594feed ( '1Gla<cr><esc>' ) 595check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 1 , 2 ) 596check_undo_redo ( ns , marks [ 2 ], 1 , 4 , 2 , 4 ) 597end ) 598 599it ( 'marks at last line move on insert new line' , function () 600-- open_line in change.c 601set_extmark ( ns , marks [ 1 ], 0 , 4 ) 602feed ( '0i<cr><esc>' ) 603check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 1 , 4 ) 604end ) 605 606it ( 'yet again marks move with line splits' , function () 607-- the first test above wasn't catching all errors.. 608feed ( 'A67890<esc>' ) 609set_extmark ( ns , marks [ 1 ], 0 , 4 ) 610feed ( '04li<cr><esc>' ) 611check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 1 , 0 ) 612end ) 613 614it ( 'and one last time line splits...' , function () 615set_extmark ( ns , marks [ 1 ], 0 , 1 ) 616set_extmark ( ns , marks [ 2 ], 0 , 2 ) 617feed ( '02li<cr><esc>' ) 618check_undo_redo ( ns , marks [ 1 ], 0 , 1 , 0 , 1 ) 619check_undo_redo ( ns , marks [ 2 ], 0 , 2 , 1 , 0 ) 620end ) 621 622it ( 'multiple marks move with mark splits' , function () 623set_extmark ( ns , marks [ 1 ], 0 , 1 ) 624set_extmark ( ns , marks [ 2 ], 0 , 3 ) 625feed ( '0li<cr><esc>' ) 626check_undo_redo ( ns , marks [ 1 ], 0 , 1 , 1 , 0 ) 627check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 1 , 2 ) 628end ) 629 630it ( 'deleting right before a mark works' , function () 631-- op_delete in ops.c 632set_extmark ( ns , marks [ 1 ], 0 , 2 ) 633feed ( '0lx' ) 634check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 1 ) 635end ) 636 637it ( 'deleting right after a mark works' , function () 638-- op_delete in ops.c 639set_extmark ( ns , marks [ 1 ], 0 , 2 ) 640feed ( '02lx' ) 641check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 642end ) 643 644it ( 'marks move with char deletes' , function () 645-- op_delete in ops.c 646set_extmark ( ns , marks [ 1 ], 0 , 2 ) 647feed ( '02dl' ) 648check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 0 ) 649-- from the other side (nothing should happen) 650feed ( '$x' ) 651check_undo_redo ( ns , marks [ 1 ], 0 , 0 , 0 , 0 ) 652end ) 653 654it ( 'marks move with char deletes over a range' , function () 655-- op_delete in ops.c 656set_extmark ( ns , marks [ 1 ], 0 , 2 ) 657set_extmark ( ns , marks [ 2 ], 0 , 3 ) 658feed ( '0l3dl<esc>' ) 659check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 1 ) 660check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 1 ) 661-- delete 1, nothing should happen to our marks 662feed ( 'u' ) 663feed ( '$x' ) 664check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 3 ) 665end ) 666 667it ( 'deleting marks at end of line works' , function () 668set_extmark ( ns , marks [ 1 ], 0 , 4 ) 669feed ( '$x' ) 670check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 0 , 4 ) 671-- check the copy happened correctly on delete at eol 672feed ( '$x' ) 673check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 0 , 3 ) 674feed ( 'u' ) 675check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 0 , 4 ) 676end ) 677 678it ( 'marks move with blockwise deletes' , function () 679-- op_delete in ops.c 680feed ( 'a<cr>12345<esc>' ) 681set_extmark ( ns , marks [ 1 ], 1 , 4 ) 682feed ( 'h<c-v>hhkd' ) 683check_undo_redo ( ns , marks [ 1 ], 1 , 4 , 1 , 1 ) 684end ) 685 686it ( 'marks move with blockwise deletes over a range' , function () 687-- op_delete in ops.c 688feed ( 'a<cr>12345<esc>' ) 689set_extmark ( ns , marks [ 1 ], 0 , 1 ) 690set_extmark ( ns , marks [ 2 ], 0 , 3 ) 691set_extmark ( ns , marks [ 3 ], 1 , 2 ) 692feed ( '0<c-v>k3lx' ) 693check_undo_redo ( ns , marks [ 1 ], 0 , 1 , 0 , 0 ) 694check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 0 ) 695check_undo_redo ( ns , marks [ 3 ], 1 , 2 , 1 , 0 ) 696-- delete 1, nothing should happen to our marks 697feed ( 'u' ) 698feed ( '$<c-v>jx' ) 699check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 3 ) 700check_undo_redo ( ns , marks [ 3 ], 1 , 2 , 1 , 2 ) 701end ) 702 703it ( 'works with char deletes over multilines' , function () 704feed ( 'a<cr>12345<cr>test-me<esc>' ) 705set_extmark ( ns , marks [ 1 ], 2 , 5 ) 706feed ( 'gg' ) 707feed ( 'dv?-m?<cr>' ) 708check_undo_redo ( ns , marks [ 1 ], 2 , 5 , 0 , 0 ) 709end ) 710 711it ( 'marks outside of deleted range move with visual char deletes' , function () 712-- op_delete in ops.c 713set_extmark ( ns , marks [ 1 ], 0 , 3 ) 714feed ( '0vx<esc>' ) 715check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 2 ) 716 717feed ( 'u' ) 718feed ( '0vlx<esc>' ) 719check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 1 ) 720 721feed ( 'u' ) 722feed ( '0v2lx<esc>' ) 723check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 0 ) 724 725-- from the other side (nothing should happen) 726feed ( '$vx' ) 727check_undo_redo ( ns , marks [ 1 ], 0 , 0 , 0 , 0 ) 728end ) 729 730it ( 'marks outside of deleted range move with char deletes' , function () 731-- op_delete in ops.c 732set_extmark ( ns , marks [ 1 ], 0 , 3 ) 733feed ( '0x<esc>' ) 734check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 2 ) 735 736feed ( 'u' ) 737feed ( '02x<esc>' ) 738check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 1 ) 739 740feed ( 'u' ) 741feed ( '0v3lx<esc>' ) 742check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 0 ) 743 744-- from the other side (nothing should happen) 745feed ( 'u' ) 746feed ( '$vx' ) 747check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 3 ) 748end ) 749 750it ( 'marks move with P(backward) paste' , function () 751-- do_put in ops.c 752feed ( '0iabc<esc>' ) 753set_extmark ( ns , marks [ 1 ], 0 , 7 ) 754feed ( '0veyP' ) 755check_undo_redo ( ns , marks [ 1 ], 0 , 7 , 0 , 15 ) 756end ) 757 758it ( 'marks move with p(forward) paste' , function () 759-- do_put in ops.c 760feed ( '0iabc<esc>' ) 761set_extmark ( ns , marks [ 1 ], 0 , 7 ) 762feed ( '0veyp' ) 763check_undo_redo ( ns , marks [ 1 ], 0 , 7 , 0 , 15 ) 764end ) 765 766it ( 'marks move with blockwise P(backward) paste' , function () 767-- do_put in ops.c 768feed ( 'a<cr>12345<esc>' ) 769set_extmark ( ns , marks [ 1 ], 1 , 4 ) 770feed ( '<c-v>hhkyP<esc>' ) 771check_undo_redo ( ns , marks [ 1 ], 1 , 4 , 1 , 7 ) 772end ) 773 774it ( 'marks move with blockwise p(forward) paste' , function () 775-- do_put in ops.c 776feed ( 'a<cr>12345<esc>' ) 777set_extmark ( ns , marks [ 1 ], 1 , 4 ) 778feed ( '<c-v>hhkyp<esc>' ) 779check_undo_redo ( ns , marks [ 1 ], 1 , 4 , 1 , 7 ) 780end ) 781 782describe ( 'multiline regions' , function () 783before_each ( function () 784feed ( 'dd' ) 785-- Achtung: code has been spiced with some unicode, 786-- to make life more interesting. 787-- luacheck whines about TABs inside strings for whatever reason. 788-- luacheck: push ignore 621 789insert ( [[ 790static int nlua_rpcrequest(lua_State *lstate) 791{ 792Ïf (!nlua_is_deferred_safe(lstate)) { 793// strictly not allowed 794Яetörn luaL_error(lstate, e_fast_api_disabled, "rpcrequest"); 795} 796return nlua_rpc(lstate, true); 797}]] ) 798-- luacheck: pop 799end ) 800 801it ( 'delete' , function () 802local pos1 ={ 803{ 2 , 4 } , 804{ 2 , 12 } , 805{ 2 , 13 } , 806{ 2 , 14 } , 807{ 2 , 25 } , 808{ 4 , 8 } , 809{ 4 , 10 } , 810{ 4 , 20 } , 811{ 5 , 3 } , 812{ 6 , 10 } , 813} 814local ids =batch_set ( ns , pos1 ) 815batch_check ( ns , ids , pos1 ) 816feed ( '3Gfiv2+ftd' ) 817batch_check_undo_redo ( ns , ids , pos1 , { 818{ 2 , 4 } , 819{ 2 , 12 } , 820{ 2 , 13 } , 821{ 2 , 13 } , 822{ 2 , 13 } , 823{ 2 , 13 } , 824{ 2 , 15 } , 825{ 2 , 25 } , 826{ 3 , 3 } , 827{ 4 , 10 } , 828} ) 829end ) 830 831it ( 'can get overlapping extmarks' , function () 832set_extmark ( ns , 1 , 0 , 0 , { end_row =5 , end_col =0 } ) 833set_extmark ( ns , 2 , 2 , 5 , { end_row =2 , end_col =30 } ) 834set_extmark ( ns , 3 , 0 , 5 , { end_row =2 , end_col =10 } ) 835set_extmark ( ns , 4 , 0 , 0 , { end_row =1 , end_col =0 } ) 836eq ( { { 2 , 2 , 5 } } , get_extmarks ( ns , { 2 , 0 } , { 2 , - 1 } , { overlap =false } )) 837eq ( 838{ { 1 , 0 , 0 } , { 3 , 0 , 5 } , { 2 , 2 , 5 } } , 839get_extmarks ( ns , { 2 , 0 } , { 2 , - 1 } , { overlap =true } ) 840) 841end ) 842 843it ( 'limits overlap results' , function () 844set_extmark ( ns , 1 , 0 , 0 , { end_row =5 , end_col =0 } ) 845set_extmark ( ns , 2 , 2 , 5 , { end_row =2 , end_col =30 } ) 846set_extmark ( ns , 3 , 0 , 5 , { end_row =2 , end_col =10 } ) 847set_extmark ( ns , 4 , 0 , 0 , { end_row =1 , end_col =0 } ) 848local rv =get_extmarks ( ns , { 2 , 0 } , { 2 , - 1 } , { overlap =true , limit =1 } ) 849eq ( 1 , # rv ) 850end ) 851end ) 852 853it ( 'replace works' , function () 854set_extmark ( ns , marks [ 1 ], 0 , 2 ) 855feed ( '0r2' ) 856check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 857end ) 858 859it ( 'blockwise replace works' , function () 860feed ( 'a<cr>12345<esc>' ) 861set_extmark ( ns , marks [ 1 ], 0 , 2 ) 862feed ( '0<c-v>llkr1<esc>' ) 863check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 3 ) 864end ) 865 866it ( 'shift line' , function () 867-- shift_line in ops.c 868feed ( ':set shiftwidth=4<cr><esc>' ) 869set_extmark ( ns , marks [ 1 ], 0 , 2 ) 870feed ( '0>>' ) 871check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 6 ) 872expect ( ' 12345' ) 873 874feed ( '>>' ) 875-- this is counter-intuitive. But what happens 876-- is that 4 spaces gets extended to one tab (== 8 spaces) 877check_undo_redo ( ns , marks [ 1 ], 0 , 6 , 0 , 3 ) 878expect ( '\t12345' ) 879 880feed ( '<LT><LT>' ) -- have to escape, same as << 881check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 6 ) 882end ) 883 884it ( 'blockwise shift' , function () 885-- shift_block in ops.c 886feed ( ':set shiftwidth=4<cr><esc>' ) 887feed ( 'a<cr>12345<esc>' ) 888set_extmark ( ns , marks [ 1 ], 1 , 2 ) 889feed ( '0<c-v>k>' ) 890check_undo_redo ( ns , marks [ 1 ], 1 , 2 , 1 , 6 ) 891-- "gg0": the cursor after undo/redo depends on |restore-undo-cursor|. 892feed ( 'gg0<c-v>j>' ) 893expect ( '\t12345\n\t12345' ) 894check_undo_redo ( ns , marks [ 1 ], 1 , 6 , 1 , 3 ) 895 896feed ( 'gg0<c-v>j<LT>' ) 897check_undo_redo ( ns , marks [ 1 ], 1 , 3 , 1 , 6 ) 898end ) 899 900it ( 'tab works with expandtab' , function () 901-- ins_tab in insert.c 902feed ( ':set expandtab<cr><esc>' ) 903feed ( ':set shiftwidth=2<cr><esc>' ) 904set_extmark ( ns , marks [ 1 ], 0 , 2 ) 905feed ( '0i<tab><tab><esc>' ) 906check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 6 ) 907end ) 908 909it ( 'tabs work' , function () 910-- ins_tab in insert.c 911feed ( ':set noexpandtab<cr><esc>' ) 912feed ( ':set shiftwidth=2<cr><esc>' ) 913feed ( ':set softtabstop=2<cr><esc>' ) 914feed ( ':set tabstop=8<cr><esc>' ) 915set_extmark ( ns , marks [ 1 ], 0 , 2 ) 916feed ( '0i<tab><esc>' ) 917check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 4 ) 918feed ( '0iX<tab><esc>' ) 919check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 0 , 6 ) 920end ) 921 922it ( 'marks move when using :move' , function () 923set_extmark ( ns , marks [ 1 ], 0 , 0 ) 924feed ( 'A<cr>2<esc>:1move 2<cr><esc>' ) 925check_undo_redo ( ns , marks [ 1 ], 0 , 0 , 1 , 0 ) 926-- test codepath when moving lines up 927feed ( ':2move 0<cr><esc>' ) 928check_undo_redo ( ns , marks [ 1 ], 1 , 0 , 0 , 0 ) 929end ) 930 931it ( 'marks move when using :move part 2' , function () 932-- make sure we didn't get lucky with the math... 933feed ( 'A<cr>2<cr>3<cr>4<cr>5<cr>6<esc>' ) 934set_extmark ( ns , marks [ 1 ], 1 , 0 ) 935feed ( ':2,3move 5<cr><esc>' ) 936check_undo_redo ( ns , marks [ 1 ], 1 , 0 , 3 , 0 ) 937-- test codepath when moving lines up 938feed ( ':4,5move 1<cr><esc>' ) 939check_undo_redo ( ns , marks [ 1 ], 3 , 0 , 1 , 0 ) 940end ) 941 942it ( 'undo and redo of set and unset marks' , function () 943-- Force a new undo head 944feed ( 'o<esc>' ) 945set_extmark ( ns , marks [ 1 ], 0 , 1 ) 946feed ( 'o<esc>' ) 947set_extmark ( ns , marks [ 2 ], 0 , - 1 ) 948set_extmark ( ns , marks [ 3 ], 0 , - 1 ) 949 950feed ( 'u' ) 951local rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } ) 952eq ( 3 , # rv ) 953 954feed ( '<c-r>' ) 955rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } ) 956eq ( 3 , # rv ) 957 958-- Test updates 959feed ( 'o<esc>' ) 960set_extmark ( ns , marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ]) 961rv =get_extmarks ( ns , marks [ 1 ], marks [ 1 ], { limit =1 } ) 962eq ( 1 , # rv ) 963feed ( 'u' ) 964feed ( '<c-r>' ) 965-- old value is NOT kept in history 966check_undo_redo ( 967ns , 968marks [ 1 ], 969positions [ 1 ][ 1 ], 970positions [ 1 ][ 2 ], 971positions [ 1 ][ 1 ], 972positions [ 1 ][ 2 ] 973) 974 975-- Test unset 976feed ( 'o<esc>' ) 977api . nvim_buf_del_extmark ( 0 , ns , marks [ 3 ]) 978feed ( 'u' ) 979rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } ) 980-- undo does NOT restore deleted marks 981eq ( 2 , # rv ) 982feed ( '<c-r>' ) 983rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } ) 984eq ( 2 , # rv ) 985end ) 986 987it ( 'undo and redo of a mark created during an edit #30331' , function () 988local function range ( id ) 989local m =get_extmark_by_id ( ns , id , { details =true } ) 990return { m [ 1 ], m [ 2 ], m [ 3 ]. end_row , m [ 3 ]. end_col , m [ 3 ]. invalid } 991end 992-- Create the marks over text the edit added, while the undo block is still open. 993feed ( 'ggdGifoobar' ) 994set_extmark ( ns , marks [ 1 ], 0 , 3 , { end_col =6 } ) 995set_extmark ( ns , marks [ 2 ], 0 , 3 , { end_col =6 , invalidate =true } ) 996feed ( '<esc>' ) 997eq ( { 0 , 3 , 0 , 6 } , range ( marks [ 1 ])) 998feed ( 'u' ) 999-- The text is gone, so the range collapses; the invalidating mark also goes invalid. 1000eq ( { 0 , 0 , 0 , 0 } , range ( marks [ 1 ])) 1001eq ( { 0 , 0 , 0 , 0 , true } , range ( marks [ 2 ])) 1002feed ( '<c-r>' ) 1003-- Redo re-applies the position each side of the range was set to, and revives the 1004-- invalidated mark; replaying the splices alone leaves the range collapsed. 1005eq ( { 0 , 3 , 0 , 6 } , range ( marks [ 1 ])) 1006eq ( { 0 , 3 , 0 , 6 } , range ( marks [ 2 ])) 1007end ) 1008 1009it ( 'undo and redo of a mark explicitly moved during an edit' , function () 1010feed ( 'ggdGiabcdef<esc>' ) 1011set_extmark ( ns , marks [ 1 ], 0 , 4 ) 1012-- Insert at col 0; while the undo block is still open, explicitly 1013-- move the mark. 1014feed ( '0i!!' ) 1015set_extmark ( ns , marks [ 1 ], 0 , 1 ) 1016feed ( '<esc>' ) 1017eq ( { 0 , 1 } , get_extmark_by_id ( ns , marks [ 1 ])) 1018feed ( 'u' ) 1019-- Back where it was before the edit (the recorded set-time position, 1020-- shifted back by the splice reversal). 1021eq ( { 0 , 4 } , get_extmark_by_id ( ns , marks [ 1 ])) 1022feed ( '<c-r>' ) 1023-- Redo restores the explicit position: splice adjustment alone would 1024-- leave the mark at col 6. 1025eq ( { 0 , 1 } , get_extmark_by_id ( ns , marks [ 1 ])) 1026end ) 1027 1028it ( 'undo and redo of marks deleted during edits' , function () 1029-- test extmark_adjust 1030feed ( 'A<cr>12345<esc>' ) 1031set_extmark ( ns , marks [ 1 ], 1 , 2 ) 1032feed ( 'dd' ) 1033check_undo_redo ( ns , marks [ 1 ], 1 , 2 , 1 , 0 ) 1034end ) 1035 1036it ( 'namespaces work properly' , function () 1037local rv =set_extmark ( ns , marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ]) 1038eq ( 1 , rv ) 1039rv =set_extmark ( ns2 , marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ]) 1040eq ( 1 , rv ) 1041rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } ) 1042eq ( 1 , # rv ) 1043rv =get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } ) 1044eq ( 1 , # rv ) 1045 1046-- Set more marks for testing the ranges 1047set_extmark ( ns , marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ]) 1048set_extmark ( ns , marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ]) 1049set_extmark ( ns2 , marks [ 2 ], positions [ 2 ][ 1 ], positions [ 2 ][ 2 ]) 1050set_extmark ( ns2 , marks [ 3 ], positions [ 3 ][ 1 ], positions [ 3 ][ 2 ]) 1051 1052-- get_next (limit set) 1053rv =get_extmarks ( ns , { 0 , 0 } , positions [ 2 ], { limit =1 } ) 1054eq ( 1 , # rv ) 1055rv =get_extmarks ( ns2 , { 0 , 0 } , positions [ 2 ], { limit =1 } ) 1056eq ( 1 , # rv ) 1057-- reverse (limit set) 1058rv =get_extmarks ( ns , positions [ 1 ], { 0 , 0 } , { limit =1 } ) 1059eq ( 1 , # rv ) 1060rv =get_extmarks ( ns2 , positions [ 1 ], { 0 , 0 } , { limit =1 } ) 1061eq ( 1 , # rv ) 1062 1063-- get_next (no limit) 1064rv =get_extmarks ( ns , positions [ 1 ], positions [ 2 ]) 1065eq ( 2 , # rv ) 1066rv =get_extmarks ( ns2 , positions [ 1 ], positions [ 2 ]) 1067eq ( 2 , # rv ) 1068-- reverse (no limit) 1069rv =get_extmarks ( ns , positions [ 2 ], positions [ 1 ]) 1070eq ( 2 , # rv ) 1071rv =get_extmarks ( ns2 , positions [ 2 ], positions [ 1 ]) 1072eq ( 2 , # rv ) 1073 1074api . nvim_buf_del_extmark ( 0 , ns , marks [ 1 ]) 1075rv =get_extmarks ( ns , { 0 , 0 } , { - 1 , - 1 } ) 1076eq ( 2 , # rv ) 1077api . nvim_buf_del_extmark ( 0 , ns2 , marks [ 1 ]) 1078rv =get_extmarks ( ns2 , { 0 , 0 } , { - 1 , - 1 } ) 1079eq ( 2 , # rv ) 1080end ) 1081 1082it ( 'mark set can create unique identifiers' , function () 1083-- create mark with id 1 1084eq ( 1 , set_extmark ( ns , 1 , positions [ 1 ][ 1 ], positions [ 1 ][ 2 ])) 1085-- ask for unique id, it should be the next one, i e 2 1086eq ( 2 , set_extmark ( ns , 0 , positions [ 1 ][ 1 ], positions [ 1 ][ 2 ])) 1087eq ( 3 , set_extmark ( ns , 3 , positions [ 2 ][ 1 ], positions [ 2 ][ 2 ])) 1088eq ( 4 , set_extmark ( ns , 0 , positions [ 1 ][ 1 ], positions [ 1 ][ 2 ])) 1089 1090-- mixing manual and allocated id:s are not recommended, but it should 1091-- do something reasonable 1092eq ( 6 , set_extmark ( ns , 6 , positions [ 2 ][ 1 ], positions [ 2 ][ 2 ])) 1093eq ( 7 , set_extmark ( ns , 0 , positions [ 1 ][ 1 ], positions [ 1 ][ 2 ])) 1094eq ( 8 , set_extmark ( ns , 0 , positions [ 1 ][ 1 ], positions [ 1 ][ 2 ])) 1095end ) 1096 1097it ( 'auto indenting with enter works' , function () 1098-- op_reindent in ops.c 1099feed ( ':set cindent<cr><esc>' ) 1100feed ( ':set autoindent<cr><esc>' ) 1101feed ( ':set shiftwidth=2<cr><esc>' ) 1102feed ( '0iint <esc>A {1M1<esc>b<esc>' ) 1103-- Set the mark on the M, should move.. 1104set_extmark ( ns , marks [ 1 ], 0 , 12 ) 1105-- Set the mark before the cursor, should stay there 1106set_extmark ( ns , marks [ 2 ], 0 , 10 ) 1107feed ( 'i<cr><esc>' ) 1108local rv =get_extmark_by_id ( ns , marks [ 1 ]) 1109eq ( { 1 , 3 } , rv ) 1110rv =get_extmark_by_id ( ns , marks [ 2 ]) 1111eq ( { 0 , 10 } , rv ) 1112check_undo_redo ( ns , marks [ 1 ], 0 , 12 , 1 , 3 ) 1113end ) 1114 1115it ( 'auto indenting entire line works' , function () 1116feed ( ':set cindent<cr><esc>' ) 1117feed ( ':set autoindent<cr><esc>' ) 1118feed ( ':set shiftwidth=2<cr><esc>' ) 1119-- <c-f> will force an indent of 2 1120feed ( '0iint <esc>A {<cr><esc>0i1M1<esc>' ) 1121set_extmark ( ns , marks [ 1 ], 1 , 1 ) 1122feed ( '0i<c-f><esc>' ) 1123local rv =get_extmark_by_id ( ns , marks [ 1 ]) 1124eq ( { 1 , 3 } , rv ) 1125check_undo_redo ( ns , marks [ 1 ], 1 , 1 , 1 , 3 ) 1126-- now check when cursor at eol 1127feed ( 'uA<c-f><esc>' ) 1128rv =get_extmark_by_id ( ns , marks [ 1 ]) 1129eq ( { 1 , 3 } , rv ) 1130end ) 1131 1132it ( 'removing auto indenting with <C-D> works' , function () 1133feed ( ':set cindent<cr><esc>' ) 1134feed ( ':set autoindent<cr><esc>' ) 1135feed ( ':set shiftwidth=2<cr><esc>' ) 1136feed ( '0i<tab><esc>' ) 1137set_extmark ( ns , marks [ 1 ], 0 , 3 ) 1138feed ( 'bi<c-d><esc>' ) 1139local rv =get_extmark_by_id ( ns , marks [ 1 ]) 1140eq ( { 0 , 1 } , rv ) 1141check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 1 ) 1142-- check when cursor at eol 1143feed ( 'uA<c-d><esc>' ) 1144rv =get_extmark_by_id ( ns , marks [ 1 ]) 1145eq ( { 0 , 1 } , rv ) 1146end ) 1147 1148it ( 'indenting multiple lines with = works' , function () 1149feed ( ':set cindent<cr><esc>' ) 1150feed ( ':set autoindent<cr><esc>' ) 1151feed ( ':set shiftwidth=2<cr><esc>' ) 1152feed ( '0iint <esc>A {<cr><bs>1M1<cr><bs>2M2<esc>' ) 1153set_extmark ( ns , marks [ 1 ], 1 , 1 ) 1154set_extmark ( ns , marks [ 2 ], 2 , 1 ) 1155feed ( '=gg' ) 1156check_undo_redo ( ns , marks [ 1 ], 1 , 1 , 1 , 3 ) 1157check_undo_redo ( ns , marks [ 2 ], 2 , 1 , 2 , 5 ) 1158end ) 1159 1160it ( 'substitutes by deleting inside the replace matches' , function () 1161-- do_sub in ex_cmds.c 1162set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1163set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1164feed ( ':s/34/xx<cr>' ) 1165check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 4 ) 1166check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 4 ) 1167end ) 1168 1169it ( 'substitutes when insert text > deleted' , function () 1170-- do_sub in ex_cmds.c 1171set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1172set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1173feed ( ':s/34/xxx<cr>' ) 1174check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 5 ) 1175check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 5 ) 1176end ) 1177 1178it ( 'substitutes when marks around eol' , function () 1179-- do_sub in ex_cmds.c 1180set_extmark ( ns , marks [ 1 ], 0 , 4 ) 1181set_extmark ( ns , marks [ 2 ], 0 , 5 ) 1182feed ( ':s/5/xxx<cr>' ) 1183check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 0 , 7 ) 1184check_undo_redo ( ns , marks [ 2 ], 0 , 5 , 0 , 7 ) 1185end ) 1186 1187it ( 'substitutes over range insert text > deleted' , function () 1188-- do_sub in ex_cmds.c 1189feed ( 'A<cr>x34xx<esc>' ) 1190feed ( 'A<cr>xxx34<esc>' ) 1191set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1192set_extmark ( ns , marks [ 2 ], 1 , 1 ) 1193set_extmark ( ns , marks [ 3 ], 2 , 4 ) 1194feed ( ':1,3s/34/xxx<cr><esc>' ) 1195check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 5 ) 1196check_undo_redo ( ns , marks [ 2 ], 1 , 1 , 1 , 4 ) 1197check_undo_redo ( ns , marks [ 3 ], 2 , 4 , 2 , 6 ) 1198end ) 1199 1200it ( 'substitutes multiple matches in a line' , function () 1201-- do_sub in ex_cmds.c 1202feed ( 'ddi3x3x3<esc>' ) 1203set_extmark ( ns , marks [ 1 ], 0 , 0 ) 1204set_extmark ( ns , marks [ 2 ], 0 , 2 ) 1205set_extmark ( ns , marks [ 3 ], 0 , 4 ) 1206feed ( ':s/3/yy/g<cr><esc>' ) 1207check_undo_redo ( ns , marks [ 1 ], 0 , 0 , 0 , 2 ) 1208check_undo_redo ( ns , marks [ 2 ], 0 , 2 , 0 , 5 ) 1209check_undo_redo ( ns , marks [ 3 ], 0 , 4 , 0 , 8 ) 1210end ) 1211 1212it ( 'substitutes over multiple lines with newline in pattern' , function () 1213feed ( 'A<cr>67890<cr>xx<esc>' ) 1214set_extmark ( ns , marks [ 1 ], 0 , 3 ) 1215set_extmark ( ns , marks [ 2 ], 0 , 4 ) 1216set_extmark ( ns , marks [ 3 ], 1 , 0 ) 1217set_extmark ( ns , marks [ 4 ], 1 , 5 ) 1218set_extmark ( ns , marks [ 5 ], 2 , 0 ) 1219feed ( [[:1,2s:5\n:5 <cr>]] ) 1220check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 3 ) 1221check_undo_redo ( ns , marks [ 2 ], 0 , 4 , 0 , 6 ) 1222check_undo_redo ( ns , marks [ 3 ], 1 , 0 , 0 , 6 ) 1223check_undo_redo ( ns , marks [ 4 ], 1 , 5 , 0 , 11 ) 1224check_undo_redo ( ns , marks [ 5 ], 2 , 0 , 1 , 0 ) 1225end ) 1226 1227it ( 'inserting' , function () 1228feed ( 'A<cr>67890<cr>xx<esc>' ) 1229set_extmark ( ns , marks [ 1 ], 0 , 3 ) 1230set_extmark ( ns , marks [ 2 ], 0 , 4 ) 1231set_extmark ( ns , marks [ 3 ], 1 , 0 ) 1232set_extmark ( ns , marks [ 4 ], 1 , 5 ) 1233set_extmark ( ns , marks [ 5 ], 2 , 0 ) 1234set_extmark ( ns , marks [ 6 ], 1 , 2 ) 1235feed ( [[:1,2s:5\n67:X<cr>]] ) 1236check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 3 ) 1237check_undo_redo ( ns , marks [ 2 ], 0 , 4 , 0 , 5 ) 1238check_undo_redo ( ns , marks [ 3 ], 1 , 0 , 0 , 5 ) 1239check_undo_redo ( ns , marks [ 4 ], 1 , 5 , 0 , 8 ) 1240check_undo_redo ( ns , marks [ 5 ], 2 , 0 , 1 , 0 ) 1241check_undo_redo ( ns , marks [ 6 ], 1 , 2 , 0 , 5 ) 1242end ) 1243 1244it ( 'substitutes with multiple newlines in pattern' , function () 1245feed ( 'A<cr>67890<cr>xx<esc>' ) 1246set_extmark ( ns , marks [ 1 ], 0 , 4 ) 1247set_extmark ( ns , marks [ 2 ], 0 , 5 ) 1248set_extmark ( ns , marks [ 3 ], 1 , 0 ) 1249set_extmark ( ns , marks [ 4 ], 1 , 5 ) 1250set_extmark ( ns , marks [ 5 ], 2 , 0 ) 1251feed ( [[:1,2s:\n.*\n:X<cr>]] ) 1252check_undo_redo ( ns , marks [ 1 ], 0 , 4 , 0 , 4 ) 1253check_undo_redo ( ns , marks [ 2 ], 0 , 5 , 0 , 6 ) 1254check_undo_redo ( ns , marks [ 3 ], 1 , 0 , 0 , 6 ) 1255check_undo_redo ( ns , marks [ 4 ], 1 , 5 , 0 , 6 ) 1256check_undo_redo ( ns , marks [ 5 ], 2 , 0 , 0 , 6 ) 1257end ) 1258 1259it ( 'substitutes over multiple lines with replace in substitution' , function () 1260feed ( 'A<cr>67890<cr>xx<esc>' ) 1261set_extmark ( ns , marks [ 1 ], 0 , 1 ) 1262set_extmark ( ns , marks [ 2 ], 0 , 2 ) 1263set_extmark ( ns , marks [ 3 ], 0 , 4 ) 1264set_extmark ( ns , marks [ 4 ], 1 , 0 ) 1265set_extmark ( ns , marks [ 5 ], 2 , 0 ) 1266feed ( [[:1,2s:3:\r<cr>]] ) 1267check_undo_redo ( ns , marks [ 1 ], 0 , 1 , 0 , 1 ) 1268check_undo_redo ( ns , marks [ 2 ], 0 , 2 , 1 , 0 ) 1269check_undo_redo ( ns , marks [ 3 ], 0 , 4 , 1 , 1 ) 1270check_undo_redo ( ns , marks [ 4 ], 1 , 0 , 2 , 0 ) 1271check_undo_redo ( ns , marks [ 5 ], 2 , 0 , 3 , 0 ) 1272feed ( 'u' ) 1273feed ( [[:1,2s:3:\rxx<cr>]] ) 1274eq ( { 1 , 3 } , get_extmark_by_id ( ns , marks [ 3 ])) 1275end ) 1276 1277it ( 'substitutes over multiple lines with replace in substitution' , function () 1278feed ( 'A<cr>x3<cr>xx<esc>' ) 1279set_extmark ( ns , marks [ 1 ], 1 , 0 ) 1280set_extmark ( ns , marks [ 2 ], 1 , 1 ) 1281set_extmark ( ns , marks [ 3 ], 1 , 2 ) 1282feed ( [[:2,2s:3:\r<cr>]] ) 1283check_undo_redo ( ns , marks [ 1 ], 1 , 0 , 1 , 0 ) 1284check_undo_redo ( ns , marks [ 2 ], 1 , 1 , 2 , 0 ) 1285check_undo_redo ( ns , marks [ 3 ], 1 , 2 , 2 , 0 ) 1286end ) 1287 1288it ( 'substitutes over multiple lines with replace in substitution' , function () 1289feed ( 'A<cr>x3<cr>xx<esc>' ) 1290set_extmark ( ns , marks [ 1 ], 0 , 1 ) 1291set_extmark ( ns , marks [ 2 ], 0 , 2 ) 1292set_extmark ( ns , marks [ 3 ], 0 , 4 ) 1293set_extmark ( ns , marks [ 4 ], 1 , 1 ) 1294set_extmark ( ns , marks [ 5 ], 2 , 0 ) 1295feed ( [[:1,2s:3:\r<cr>]] ) 1296check_undo_redo ( ns , marks [ 1 ], 0 , 1 , 0 , 1 ) 1297check_undo_redo ( ns , marks [ 2 ], 0 , 2 , 1 , 0 ) 1298check_undo_redo ( ns , marks [ 3 ], 0 , 4 , 1 , 1 ) 1299check_undo_redo ( ns , marks [ 4 ], 1 , 1 , 3 , 0 ) 1300check_undo_redo ( ns , marks [ 5 ], 2 , 0 , 4 , 0 ) 1301feed ( 'u' ) 1302feed ( [[:1,2s:3:\rxx<cr>]] ) 1303check_undo_redo ( ns , marks [ 3 ], 0 , 4 , 1 , 3 ) 1304end ) 1305 1306it ( 'substitutes with newline in match and sub, delta is 0' , function () 1307feed ( 'A<cr>67890<cr>xx<esc>' ) 1308set_extmark ( ns , marks [ 1 ], 0 , 3 ) 1309set_extmark ( ns , marks [ 2 ], 0 , 4 ) 1310set_extmark ( ns , marks [ 3 ], 0 , 5 ) 1311set_extmark ( ns , marks [ 4 ], 1 , 0 ) 1312set_extmark ( ns , marks [ 5 ], 1 , 5 ) 1313set_extmark ( ns , marks [ 6 ], 2 , 0 ) 1314feed ( [[:1,1s:5\n:\r<cr>]] ) 1315check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 3 ) 1316check_undo_redo ( ns , marks [ 2 ], 0 , 4 , 1 , 0 ) 1317check_undo_redo ( ns , marks [ 3 ], 0 , 5 , 1 , 0 ) 1318check_undo_redo ( ns , marks [ 4 ], 1 , 0 , 1 , 0 ) 1319check_undo_redo ( ns , marks [ 5 ], 1 , 5 , 1 , 5 ) 1320check_undo_redo ( ns , marks [ 6 ], 2 , 0 , 2 , 0 ) 1321end ) 1322 1323it ( 'substitutes with newline in match and sub, delta > 0' , function () 1324feed ( 'A<cr>67890<cr>xx<esc>' ) 1325set_extmark ( ns , marks [ 1 ], 0 , 3 ) 1326set_extmark ( ns , marks [ 2 ], 0 , 4 ) 1327set_extmark ( ns , marks [ 3 ], 0 , 5 ) 1328set_extmark ( ns , marks [ 4 ], 1 , 0 ) 1329set_extmark ( ns , marks [ 5 ], 1 , 5 ) 1330set_extmark ( ns , marks [ 6 ], 2 , 0 ) 1331feed ( [[:1,1s:5\n:\r\r<cr>]] ) 1332check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 3 ) 1333check_undo_redo ( ns , marks [ 2 ], 0 , 4 , 2 , 0 ) 1334check_undo_redo ( ns , marks [ 3 ], 0 , 5 , 2 , 0 ) 1335check_undo_redo ( ns , marks [ 4 ], 1 , 0 , 2 , 0 ) 1336check_undo_redo ( ns , marks [ 5 ], 1 , 5 , 2 , 5 ) 1337check_undo_redo ( ns , marks [ 6 ], 2 , 0 , 3 , 0 ) 1338end ) 1339 1340it ( 'substitutes with newline in match and sub, delta < 0' , function () 1341feed ( 'A<cr>67890<cr>xx<cr>xx<esc>' ) 1342set_extmark ( ns , marks [ 1 ], 0 , 3 ) 1343set_extmark ( ns , marks [ 2 ], 0 , 4 ) 1344set_extmark ( ns , marks [ 3 ], 0 , 5 ) 1345set_extmark ( ns , marks [ 4 ], 1 , 0 ) 1346set_extmark ( ns , marks [ 5 ], 1 , 5 ) 1347set_extmark ( ns , marks [ 6 ], 2 , 1 ) 1348set_extmark ( ns , marks [ 7 ], 3 , 0 ) 1349feed ( [[:1,2s:5\n.*\n:\r<cr>]] ) 1350check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 3 ) 1351check_undo_redo ( ns , marks [ 2 ], 0 , 4 , 1 , 0 ) 1352check_undo_redo ( ns , marks [ 3 ], 0 , 5 , 1 , 0 ) 1353check_undo_redo ( ns , marks [ 4 ], 1 , 0 , 1 , 0 ) 1354check_undo_redo ( ns , marks [ 5 ], 1 , 5 , 1 , 0 ) 1355check_undo_redo ( ns , marks [ 6 ], 2 , 1 , 1 , 1 ) 1356check_undo_redo ( ns , marks [ 7 ], 3 , 0 , 2 , 0 ) 1357end ) 1358 1359it ( 'substitutes with backrefs, newline inserted into sub' , function () 1360feed ( 'A<cr>67890<cr>xx<cr>xx<esc>' ) 1361set_extmark ( ns , marks [ 1 ], 0 , 3 ) 1362set_extmark ( ns , marks [ 2 ], 0 , 4 ) 1363set_extmark ( ns , marks [ 3 ], 0 , 5 ) 1364set_extmark ( ns , marks [ 4 ], 1 , 0 ) 1365set_extmark ( ns , marks [ 5 ], 1 , 5 ) 1366set_extmark ( ns , marks [ 6 ], 2 , 0 ) 1367feed ( [[:1,1s:5\(\n\):\0\1<cr>]] ) 1368check_undo_redo ( ns , marks [ 1 ], 0 , 3 , 0 , 3 ) 1369check_undo_redo ( ns , marks [ 2 ], 0 , 4 , 2 , 0 ) 1370check_undo_redo ( ns , marks [ 3 ], 0 , 5 , 2 , 0 ) 1371check_undo_redo ( ns , marks [ 4 ], 1 , 0 , 2 , 0 ) 1372check_undo_redo ( ns , marks [ 5 ], 1 , 5 , 2 , 5 ) 1373check_undo_redo ( ns , marks [ 6 ], 2 , 0 , 3 , 0 ) 1374end ) 1375 1376it ( 'substitutes a ^' , function () 1377set_extmark ( ns , marks [ 1 ], 0 , 0 ) 1378set_extmark ( ns , marks [ 2 ], 0 , 1 ) 1379feed ( [[:s:^:x<cr>]] ) 1380check_undo_redo ( ns , marks [ 1 ], 0 , 0 , 0 , 1 ) 1381check_undo_redo ( ns , marks [ 2 ], 0 , 1 , 0 , 2 ) 1382end ) 1383 1384it ( 'using <c-a> without increase in order of magnitude' , function () 1385-- do_addsub in ops.c 1386feed ( 'ddiabc998xxx<esc>Tc' ) 1387set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1388set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1389set_extmark ( ns , marks [ 3 ], 0 , 5 ) 1390set_extmark ( ns , marks [ 4 ], 0 , 6 ) 1391set_extmark ( ns , marks [ 5 ], 0 , 7 ) 1392feed ( '<c-a>' ) 1393check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1394check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 6 ) 1395check_undo_redo ( ns , marks [ 3 ], 0 , 5 , 0 , 6 ) 1396check_undo_redo ( ns , marks [ 4 ], 0 , 6 , 0 , 6 ) 1397check_undo_redo ( ns , marks [ 5 ], 0 , 7 , 0 , 7 ) 1398end ) 1399 1400it ( 'using <c-a> when increase in order of magnitude' , function () 1401-- do_addsub in ops.c 1402feed ( 'ddiabc999xxx<esc>Tc' ) 1403set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1404set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1405set_extmark ( ns , marks [ 3 ], 0 , 5 ) 1406set_extmark ( ns , marks [ 4 ], 0 , 6 ) 1407set_extmark ( ns , marks [ 5 ], 0 , 7 ) 1408feed ( '<c-a>' ) 1409check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1410check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 7 ) 1411check_undo_redo ( ns , marks [ 3 ], 0 , 5 , 0 , 7 ) 1412check_undo_redo ( ns , marks [ 4 ], 0 , 6 , 0 , 7 ) 1413check_undo_redo ( ns , marks [ 5 ], 0 , 7 , 0 , 8 ) 1414end ) 1415 1416it ( 'using <c-a> when negative and without decrease in order of magnitude' , function () 1417feed ( 'ddiabc-999xxx<esc>T-' ) 1418set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1419set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1420set_extmark ( ns , marks [ 3 ], 0 , 6 ) 1421set_extmark ( ns , marks [ 4 ], 0 , 7 ) 1422set_extmark ( ns , marks [ 5 ], 0 , 8 ) 1423feed ( '<c-a>' ) 1424check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1425check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 7 ) 1426check_undo_redo ( ns , marks [ 3 ], 0 , 6 , 0 , 7 ) 1427check_undo_redo ( ns , marks [ 4 ], 0 , 7 , 0 , 7 ) 1428check_undo_redo ( ns , marks [ 5 ], 0 , 8 , 0 , 8 ) 1429end ) 1430 1431it ( 'using <c-a> when negative and decrease in order of magnitude' , function () 1432feed ( 'ddiabc-1000xxx<esc>T-' ) 1433set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1434set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1435set_extmark ( ns , marks [ 3 ], 0 , 7 ) 1436set_extmark ( ns , marks [ 4 ], 0 , 8 ) 1437set_extmark ( ns , marks [ 5 ], 0 , 9 ) 1438feed ( '<c-a>' ) 1439check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1440check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 7 ) 1441check_undo_redo ( ns , marks [ 3 ], 0 , 7 , 0 , 7 ) 1442check_undo_redo ( ns , marks [ 4 ], 0 , 8 , 0 , 7 ) 1443check_undo_redo ( ns , marks [ 5 ], 0 , 9 , 0 , 8 ) 1444end ) 1445 1446it ( 'using <c-x> without decrease in order of magnitude' , function () 1447-- do_addsub in ops.c 1448feed ( 'ddiabc999xxx<esc>Tc' ) 1449set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1450set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1451set_extmark ( ns , marks [ 3 ], 0 , 5 ) 1452set_extmark ( ns , marks [ 4 ], 0 , 6 ) 1453set_extmark ( ns , marks [ 5 ], 0 , 7 ) 1454feed ( '<c-x>' ) 1455check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1456check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 6 ) 1457check_undo_redo ( ns , marks [ 3 ], 0 , 5 , 0 , 6 ) 1458check_undo_redo ( ns , marks [ 4 ], 0 , 6 , 0 , 6 ) 1459check_undo_redo ( ns , marks [ 5 ], 0 , 7 , 0 , 7 ) 1460end ) 1461 1462it ( 'using <c-x> when decrease in order of magnitude' , function () 1463-- do_addsub in ops.c 1464feed ( 'ddiabc1000xxx<esc>Tc' ) 1465set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1466set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1467set_extmark ( ns , marks [ 3 ], 0 , 6 ) 1468set_extmark ( ns , marks [ 4 ], 0 , 7 ) 1469set_extmark ( ns , marks [ 5 ], 0 , 8 ) 1470feed ( '<c-x>' ) 1471check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1472check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 6 ) 1473check_undo_redo ( ns , marks [ 3 ], 0 , 6 , 0 , 6 ) 1474check_undo_redo ( ns , marks [ 4 ], 0 , 7 , 0 , 6 ) 1475check_undo_redo ( ns , marks [ 5 ], 0 , 8 , 0 , 7 ) 1476end ) 1477 1478it ( 'using <c-x> when negative and without increase in order of magnitude' , function () 1479feed ( 'ddiabc-998xxx<esc>T-' ) 1480set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1481set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1482set_extmark ( ns , marks [ 3 ], 0 , 6 ) 1483set_extmark ( ns , marks [ 4 ], 0 , 7 ) 1484set_extmark ( ns , marks [ 5 ], 0 , 8 ) 1485feed ( '<c-x>' ) 1486check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1487check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 7 ) 1488check_undo_redo ( ns , marks [ 3 ], 0 , 6 , 0 , 7 ) 1489check_undo_redo ( ns , marks [ 4 ], 0 , 7 , 0 , 7 ) 1490check_undo_redo ( ns , marks [ 5 ], 0 , 8 , 0 , 8 ) 1491end ) 1492 1493it ( 'using <c-x> when negative and increase in order of magnitude' , function () 1494feed ( 'ddiabc-999xxx<esc>T-' ) 1495set_extmark ( ns , marks [ 1 ], 0 , 2 ) 1496set_extmark ( ns , marks [ 2 ], 0 , 3 ) 1497set_extmark ( ns , marks [ 3 ], 0 , 6 ) 1498set_extmark ( ns , marks [ 4 ], 0 , 7 ) 1499set_extmark ( ns , marks [ 5 ], 0 , 8 ) 1500feed ( '<c-x>' ) 1501check_undo_redo ( ns , marks [ 1 ], 0 , 2 , 0 , 2 ) 1502check_undo_redo ( ns , marks [ 2 ], 0 , 3 , 0 , 8 ) 1503check_undo_redo ( ns , marks [ 3 ], 0 , 6 , 0 , 8 ) 1504check_undo_redo ( ns , marks [ 4 ], 0 , 7 , 0 , 8 ) 1505check_undo_redo ( ns , marks [ 5 ], 0 , 8 , 0 , 9 ) 1506end ) 1507 1508it ( 'throws consistent error codes' , function () 1509local ns_invalid =ns2 + 1 ---@type integer 1510local err =string . format ( "Invalid 'ns_id': %d" , ns_invalid ) 1511eq ( err , pcall_err ( set_extmark , ns_invalid , marks [ 1 ], positions [ 1 ][ 1 ], positions [ 1 ][ 2 ])) 1512eq ( err , pcall_err ( api . nvim_buf_del_extmark , 0 , ns_invalid , marks [ 1 ])) 1513eq ( err , pcall_err ( get_extmarks , ns_invalid , positions [ 1 ], positions [ 2 ])) 1514eq ( err , pcall_err ( get_extmark_by_id , ns_invalid , marks [ 1 ])) 1515end ) 1516 1517it ( 'when col = line-length, set the mark on eol' , function () 1518set_extmark ( ns , marks [ 1 ], 0 , - 1 ) 1519local rv =get_extmark_by_id ( ns , marks [ 1 ]) 1520eq ( { 0 , init_text : len () } , rv ) 1521-- Test another 1522set_extmark ( ns , marks [ 1 ], 0 , - 1 ) 1523rv =get_extmark_by_id ( ns , marks [ 1 ]) 1524eq ( { 0 , init_text : len () } , rv ) 1525end ) 1526 1527it ( 'when col = line-length, set the mark on eol' , function () 1528local invalid_col =init_text : len () + 1 1529eq ( "Invalid 'col': out of range" , pcall_err ( set_extmark , ns , marks [ 1 ], 0 , invalid_col )) 1530end ) 1531 1532it ( 'fails when line > line_count' , function () 1533local invalid_col =init_text : len () + 1 1534local invalid_lnum =3 1535eq ( 1536"Invalid 'line': out of range" , 1537pcall_err ( set_extmark , ns , marks [ 1 ], invalid_lnum , invalid_col ) 1538) 1539eq ( {} , get_extmark_by_id ( ns , marks [ 1 ])) 1540end ) 1541 1542it ( 'bug from check_col in extmark_set' , function () 1543-- This bug was caused by extmark_set always using check_col. check_col 1544-- always uses the current buffer. This wasn't working during undo so we 1545-- now use check_col and check_lnum only when they are required. 1546feed ( 'A<cr>67890<cr>xx<esc>' ) 1547feed ( 'A<cr>12345<cr>67890<cr>xx<esc>' ) 1548set_extmark ( ns , marks [ 1 ], 3 , 4 ) 1549feed ( [[:1,5s:5\n:5 <cr>]] ) 1550check_undo_redo ( ns , marks [ 1 ], 3 , 4 , 2 , 6 ) 1551end ) 1552 1553it ( 'in read-only buffer' , function () 1554command ( 'view! runtime/doc/help.txt' ) 1555eq ( true , api . nvim_get_option_value ( 'ro' , {} )) 1556local id =set_extmark ( ns , 0 , 0 , 2 ) 1557eq ( { { id , 0 , 2 } } , get_extmarks ( ns , 0 , - 1 )) 1558end ) 1559 1560it ( 'can set a mark to other buffer' , function () 1561local buf =request ( 'nvim_create_buf' , 0 , 1 ) 1562request ( 'nvim_buf_set_lines' , buf , 0 , - 1 , 1 , { '' , '' } ) 1563local id =api . nvim_buf_set_extmark ( buf , ns , 1 , 0 , {} ) 1564eq ( { { id , 1 , 0 } } , api . nvim_buf_get_extmarks ( buf , ns , 0 , - 1 , {} )) 1565end ) 1566 1567it ( 'does not crash with append/delete/undo sequence' , function () 1568exec ( [[ 1569let ns = nvim_create_namespace('myplugin') 1570call nvim_buf_set_extmark(0, ns, 0, 0, {}) 1571call append(0, '') 1572%delete 1573undo]] ) 1574assert_alive () 1575end ) 1576 1577it ( 'works with left and right gravity' , function () 1578-- right gravity should move with inserted text, while 1579-- left gravity should stay in place. 1580api . nvim_buf_set_extmark ( 0 , ns , 0 , 5 , { right_gravity =false } ) 1581api . nvim_buf_set_extmark ( 0 , ns , 0 , 5 , { right_gravity =true } ) 1582feed ( [[Aasdfasdf]] ) 1583 1584eq ( { { 1 , 0 , 5 } , { 2 , 0 , 13 } } , api . nvim_buf_get_extmarks ( 0 , ns , 0 , - 1 , {} )) 1585 1586-- but both move when text is inserted before 1587feed ( [[<esc>Iasdf<esc>]] ) 1588-- eq({}, api.nvim_buf_get_lines(0, 0, -1, true)) 1589eq ( { { 1 , 0 , 9 } , { 2 , 0 , 17 } } , api . nvim_buf_get_extmarks ( 0 , ns , 0 , - 1 , {} )) 1590 1591-- clear text 1592api . nvim_buf_set_text ( 0 , 0 , 0 , 0 , 17 , {} ) 1593 1594-- handles set_text correctly as well 1595eq ( { { 1 , 0 , 0 } , { 2 , 0 , 0 } } , api . nvim_buf_get_extmarks ( 0 , ns , 0 , - 1 , {} )) 1596api . nvim_buf_set_text ( 0 , 0 , 0 , 0 , 0 , { 'asdfasdf' } ) 1597eq ( { { 1 , 0 , 0 } , { 2 , 0 , 8 } } , api . nvim_buf_get_extmarks ( 0 , ns , 0 , - 1 , {} )) 1598 1599feed ( 'u' ) 1600-- handles pasting 1601exec ( [[let @a='asdfasdf']] ) 1602feed ( [["ap]] ) 1603eq ( { { 1 , 0 , 0 } , { 2 , 0 , 8 } } , api . nvim_buf_get_extmarks ( 0 , ns , 0 , - 1 , {} )) 1604end ) 1605 1606it ( 'can accept "end_row" or "end_line" #16548' , function () 1607set_extmark ( ns , marks [ 1 ], 0 , 0 , { 1608end_col =0 , 1609end_line =1 , 1610} ) 1611eq ( { 1612{ 16131 , 16140 , 16150 , 1616{ 1617ns_id =ns , 1618end_col =0 , 1619end_row =1 , 1620right_gravity =true , 1621end_right_gravity =false , 1622} , 1623} , 1624} , get_extmarks ( ns , 0 , - 1 , { details =true } )) 1625end ) 1626 1627it ( 'in prompt buffer' , function () 1628feed ( 'dd' ) 1629set_extmark ( ns , marks [ 1 ], 0 , 0 , {} ) 1630api . nvim_set_option_value ( 'buftype' , 'prompt' , {} ) 1631feed ( 'i<esc>' ) 1632eq ( { { marks [ 1 ], 0 , 2 } } , get_extmarks ( ns , 0 , - 1 )) 1633fn . prompt_setprompt ( '' , 'foo > ' ) 1634eq ( { { marks [ 1 ], 0 , 6 } } , get_extmarks ( ns , 0 , - 1 )) 1635feed ( 'ihello' ) 1636eq ( { { marks [ 1 ], 0 , 11 } } , get_extmarks ( ns , 0 , - 1 )) 1637 1638local function get_extmark_range ( id ) 1639local rv =get_extmark_by_id ( ns , id , { details =true } ) 1640return rv [ 3 ]. invalid and 'invalid' or { rv [ 1 ], rv [ 2 ], rv [ 3 ]. end_row , rv [ 3 ]. end_col } 1641end 1642 1643set_extmark ( ns , marks [ 2 ], 0 , 0 , { invalidate =true , end_col =6 } ) 1644set_extmark ( ns , marks [ 3 ], 0 , 6 , { invalidate =true , end_col =11 } ) 1645set_extmark ( ns , marks [ 4 ], 0 , 0 , { invalidate =true , end_col =11 } ) 1646set_extmark ( ns , marks [ 5 ], 0 , 0 , { invalidate =true , end_row =1 } ) 1647fn . prompt_setprompt ( '' , 'floob > ' ) 1648eq ( { 0 , 13 } , get_extmark_range ( marks [ 1 ])) 1649eq ( 'invalid' , get_extmark_range ( marks [ 2 ])) -- extmark spanning old prompt invalidated 1650eq ( { 0 , 8 , 0 , 13 } , get_extmark_range ( marks [ 3 ])) 1651eq ( { 0 , 8 , 0 , 13 } , get_extmark_range ( marks [ 4 ])) 1652eq ( { 0 , 8 , 1 , 0 } , get_extmark_range ( marks [ 5 ])) 1653 1654set_extmark ( ns , marks [ 2 ], 0 , 0 , { invalidate =true , end_col =8 } ) 1655set_extmark ( ns , marks [ 3 ], 0 , 8 , { invalidate =true , end_col =13 } ) 1656set_extmark ( ns , marks [ 4 ], 0 , 0 , { invalidate =true , end_col =13 } ) 1657set_extmark ( ns , marks [ 5 ], 0 , 0 , { invalidate =true , end_row =1 } ) 1658-- Do this in the same event. 1659exec_lua ( function () 1660vim . fn . setpos ( "':" , { 0 , 1 , 999 , 0 } ) 1661vim . fn . prompt_setprompt ( '' , 'discard > ' ) 1662end ) 1663eq ( { 0 , 10 } , get_extmark_range ( marks [ 1 ])) 1664eq ( 'invalid' , get_extmark_range ( marks [ 2 ])) -- all spans on line invalidated 1665eq ( 'invalid' , get_extmark_range ( marks [ 3 ])) 1666eq ( 'invalid' , get_extmark_range ( marks [ 4 ])) 1667eq ( { 0 , 10 , 1 , 0 } , get_extmark_range ( marks [ 5 ])) 1668 1669feed ( 'hello' ) 1670eq ( { 0 , 15 } , get_extmark_range ( marks [ 1 ])) 1671eq ( { 0 , 15 , 1 , 0 } , get_extmark_range ( marks [ 5 ])) 1672-- init_prompt uses correct range for inserted_bytes when fixing empty prompt. 1673fn . setline ( '.' , { '' , 'last line' } ) 1674eq ( { 'discard > ' , 'last line' } , api . nvim_buf_get_lines ( 0 , 0 , - 1 , true )) 1675eq ( { 0 , 10 } , get_extmark_range ( marks [ 1 ])) 1676eq ( { 0 , 10 , 1 , 0 } , get_extmark_range ( marks [ 5 ])) 1677end ) 1678 1679it ( 'can get details' , function () 1680set_extmark ( ns , marks [ 1 ], 0 , 0 , { 1681conceal ='c' , 1682conceal_lines ='' , 1683cursorline_hl_group ='Statement' , 1684end_col =0 , 1685end_right_gravity =true , 1686end_row =1 , 1687hl_eol =true , 1688hl_group ='String' , 1689hl_mode ='blend' , 1690line_hl_group ='Statement' , 1691number_hl_group ='Statement' , 1692priority =0 , 1693right_gravity =false , 1694sign_hl_group ='Statement' , 1695sign_text ='>>' , 1696spell =true , 1697virt_lines ={ 1698{ { 'lines' , 'Macro' } , { '???' } , { ';;;' , '' } } , 1699{ { 'stack' , { 'Type' , 'Search' } } , { '!!!' } } , 1700} , 1701virt_lines_above =true , 1702virt_lines_leftcol =true , 1703virt_text ={ { 'text' , 'Macro' } , { '???' } , { 'stack' , { 'Type' , 'Search' } } } , 1704virt_text_hide =true , 1705virt_text_pos ='right_align' , 1706} ) 1707eq ( { 17080 , 17090 , 1710{ 1711conceal ='c' , 1712conceal_lines ='' , 1713cursorline_hl_group ='Statement' , 1714end_col =0 , 1715end_right_gravity =true , 1716end_row =1 , 1717hl_eol =true , 1718hl_group ='String' , 1719hl_mode ='blend' , 1720line_hl_group ='Statement' , 1721ns_id =ns , 1722number_hl_group ='Statement' , 1723priority =0 , 1724right_gravity =false , 1725sign_hl_group ='Statement' , 1726sign_text ='>>' , 1727spell =true , 1728virt_lines ={ 1729{ { 'lines' , 'Macro' } , { '???' } , { ';;;' , '' } } , 1730{ { 'stack' , { 'Type' , 'Search' } } , { '!!!' } } , 1731} , 1732virt_lines_above =true , 1733virt_lines_leftcol =true , 1734virt_lines_overflow ='trunc' , 1735virt_text ={ { 'text' , 'Macro' } , { '???' } , { 'stack' , { 'Type' , 'Search' } } } , 1736virt_text_repeat_linebreak =false , 1737virt_text_hide =true , 1738virt_text_pos ='right_align' , 1739} , 1740} , get_extmark_by_id ( ns , marks [ 1 ], { details =true } )) 1741 1742set_extmark ( ns , marks [ 2 ], 0 , 0 , { 1743priority =0 , 1744virt_text ={ { '' , 'Macro' } , { '' , { 'Type' , 'Search' } } , { '' } } , 1745virt_text_repeat_linebreak =true , 1746virt_text_win_col =1 , 1747} ) 1748eq ( { 17490 , 17500 , 1751{ 1752ns_id =ns , 1753right_gravity =true , 1754priority =0 , 1755virt_text ={ { '' , 'Macro' } , { '' , { 'Type' , 'Search' } } , { '' } } , 1756virt_text_repeat_linebreak =true , 1757virt_text_hide =false , 1758virt_text_pos ='win_col' , 1759virt_text_win_col =1 , 1760} , 1761} , get_extmark_by_id ( ns , marks [ 2 ], { details =true } )) 1762 1763set_extmark ( ns , marks [ 3 ], 0 , 0 , { 1764priority =0 , 1765ui_watched =true , 1766virt_lines ={ { { '' , 'Macro' } , { '' } , { '' , '' } } } , 1767virt_lines_overflow ='scroll' , 1768} ) 1769eq ( { 17700 , 17710 , 1772{ 1773ns_id =ns , 1774right_gravity =true , 1775ui_watched =true , 1776priority =0 , 1777virt_lines ={ { { '' , 'Macro' } , { '' } , { '' , '' } } } , 1778virt_lines_above =false , 1779virt_lines_leftcol =false , 1780virt_lines_overflow ='scroll' , 1781} , 1782} , get_extmark_by_id ( ns , marks [ 3 ], { details =true } )) 1783 1784-- verify 'wrap' is returned through get_extmark_by_id to validate flag comparison 1785set_extmark ( ns , marks [ 4 ], 0 , 0 , { 1786priority =0 , 1787ui_watched =true , 1788virt_lines ={ { { '' , 'Macro' } , { '' } , { '' , '' } } } , 1789virt_lines_overflow ='wrap' , 1790} ) 1791eq ( { 17920 , 17930 , 1794{ 1795ns_id =ns , 1796right_gravity =true , 1797ui_watched =true , 1798priority =0 , 1799virt_lines ={ { { '' , 'Macro' } , { '' } , { '' , '' } } } , 1800virt_lines_above =false , 1801virt_lines_leftcol =false , 1802virt_lines_overflow ='wrap' , 1803} , 1804} , get_extmark_by_id ( ns , marks [ 4 ], { details =true } )) 1805 1806-- verify 'auto' is returned through get_extmark_by_id to validate flag comparison 1807set_extmark ( ns , marks [ 5 ], 0 , 0 , { 1808priority =0 , 1809ui_watched =true , 1810virt_lines ={ { { '' , 'Macro' } , { '' } , { '' , '' } } } , 1811virt_lines_overflow ='auto' , 1812} ) 1813eq ( { 18140 , 18150 , 1816{ 1817ns_id =ns , 1818right_gravity =true , 1819ui_watched =true , 1820priority =0 , 1821virt_lines ={ { { '' , 'Macro' } , { '' } , { '' , '' } } } , 1822virt_lines_above =false , 1823virt_lines_leftcol =false , 1824virt_lines_overflow ='auto' , 1825} , 1826} , get_extmark_by_id ( ns , marks [ 5 ], { details =true } )) 1827 1828set_extmark ( ns , marks [ 4 ], 0 , 0 , { cursorline_hl_group ='Statement' } ) 1829eq ( { 18300 , 18310 , 1832{ 1833ns_id =ns , 1834cursorline_hl_group ='Statement' , 1835priority =4096 , 1836right_gravity =true , 1837} , 1838} , get_extmark_by_id ( ns , marks [ 4 ], { details =true } )) 1839 1840set_extmark ( ns , marks [ 5 ], 0 , 0 , { 1841end_col =1 , 1842conceal ='a' , 1843spell =true , 1844} ) 1845eq ( { 18460 , 18470 , 1848{ 1849conceal ='a' , 1850end_col =1 , 1851end_right_gravity =false , 1852end_row =0 , 1853ns_id =ns , 1854right_gravity =true , 1855spell =true , 1856} , 1857} , get_extmark_by_id ( ns , marks [ 5 ], { details =true } )) 1858 1859set_extmark ( ns , marks [ 6 ], 0 , 0 , { 1860end_col =1 , 1861spell =false , 1862} ) 1863eq ( { 18640 , 18650 , 1866{ 1867end_col =1 , 1868end_right_gravity =false , 1869end_row =0 , 1870ns_id =ns , 1871right_gravity =true , 1872spell =false , 1873} , 1874} , get_extmark_by_id ( ns , marks [ 6 ], { details =true } )) 1875 1876api . nvim_buf_clear_namespace ( 0 , ns , 0 , - 1 ) 1877-- legacy sign mark includes sign name 1878command ( 'sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine' ) 1879command ( 'sign place 1 name=sign1 line=1' ) 1880eq ( { 1881{ 18821 , 18830 , 18840 , 1885{ 1886cursorline_hl_group ='CursorLine' , 1887invalidate =true , 1888line_hl_group ='LineNr' , 1889ns_id =0 , 1890number_hl_group ='Normal' , 1891priority =10 , 1892right_gravity =true , 1893sign_hl_group ='Title' , 1894sign_name ='sign1' , 1895sign_text ='s1' , 1896undo_restore =false , 1897} , 1898} , 1899} , get_extmarks ( - 1 , 0 , - 1 , { details =true } )) 1900end ) 1901 1902it ( 'can get marks from anonymous namespaces' , function () 1903ns =request ( 'nvim_create_namespace' , '' ) 1904ns2 =request ( 'nvim_create_namespace' , '' ) 1905set_extmark ( ns , 1 , 0 , 0 , {} ) 1906set_extmark ( ns2 , 2 , 1 , 0 , {} ) 1907eq ( { 1908{ 1 , 0 , 0 , { ns_id =ns , right_gravity =true } } , 1909{ 2 , 1 , 0 , { ns_id =ns2 , right_gravity =true } } , 1910} , get_extmarks ( - 1 , 0 , - 1 , { details =true } )) 1911end ) 1912 1913it ( 'can filter by extmark properties' , function () 1914set_extmark ( ns , 1 , 0 , 0 , {} ) 1915set_extmark ( ns , 2 , 0 , 0 , { hl_group ='Normal' } ) 1916set_extmark ( ns , 3 , 0 , 0 , { sign_text ='>>' } ) 1917set_extmark ( ns , 4 , 0 , 0 , { virt_text ={ { 'text' , 'Normal' } } } ) 1918set_extmark ( ns , 5 , 0 , 0 , { virt_lines ={ { { 'line' , 'Normal' } } } } ) 1919eq ( 5 , # get_extmarks ( - 1 , 0 , - 1 , {} )) 1920eq ( { { 2 , 0 , 0 } } , get_extmarks ( - 1 , 0 , - 1 , { type ='highlight' } )) 1921eq ( { { 3 , 0 , 0 } } , get_extmarks ( - 1 , 0 , - 1 , { type ='sign' } )) 1922eq ( { { 4 , 0 , 0 } } , get_extmarks ( - 1 , 0 , - 1 , { type ='virt_text' } )) 1923eq ( { { 5 , 0 , 0 } } , get_extmarks ( - 1 , 0 , - 1 , { type ='virt_lines' } )) 1924end ) 1925 1926it ( 'invalidated marks are deleted' , function () 1927screen =Screen . new ( 40 , 6 ) 1928feed ( 'dd6iaaa bbb ccc<CR><ESC>gg' ) 1929api . nvim_set_option_value ( 'signcolumn' , 'auto:3' , {} ) 1930set_extmark ( ns , 1 , 0 , 0 , { invalidate =true , sign_text ='S1' , end_row =1 } ) 1931set_extmark ( ns , 2 , 1 , 0 , { invalidate =true , sign_text ='S2' , end_row =2 , end_col =0 } ) 1932set_extmark ( ns , 3 , 1 , 0 , { invalidate =true , sign_text ='S3' , end_row =2 , end_col =1 } ) 1933-- mark with invalidate is removed 1934command ( 'd2' ) 1935screen : expect ( [[ 1936{7:S3}^aaa bbb ccc | 1937{7: }aaa bbb ccc |*3 1938{7: } | 1939| 1940]] ) 1941-- mark is restored with undo_restore == true 1942command ( 'silent undo' ) 1943screen : expect ( [[ 1944{7:S1 }^aaa bbb ccc | 1945{7:S3S2S1}aaa bbb ccc | 1946{7:S3S2 }aaa bbb ccc | 1947{7: }aaa bbb ccc |*2 1948| 1949]] ) 1950-- decor is not removed twice 1951command ( 'd3' ) 1952api . nvim_buf_del_extmark ( 0 , ns , 1 ) 1953api . nvim_buf_del_extmark ( 0 , ns , 3 ) 1954command ( 'silent undo' ) 1955-- mark is deleted with undo_restore == false 1956set_extmark ( ns , 1 , 0 , 0 , { invalidate =true , undo_restore =false , sign_text ='S1' } ) 1957set_extmark ( ns , 2 , 1 , 0 , { invalidate =true , undo_restore =false , sign_text ='S2' } ) 1958command ( '1d 2' ) 1959eq ( 0 , # get_extmarks ( - 1 , 0 , - 1 , {} )) 1960-- mark is not removed when deleting bytes before the range 1961set_extmark ( ns , 3 , 0 , 4 , { 1962invalidate =true , 1963hl_group ='Error' , 1964end_col =7 , 1965right_gravity =false , 1966} ) 1967feed ( 'dw' ) 1968eq ( 3 , get_extmark_by_id ( ns , 3 , { details =true } )[ 3 ]. end_col ) 1969-- mark is not removed when deleting bytes at the start of the range 1970feed ( 'x' ) 1971eq ( 2 , get_extmark_by_id ( ns , 3 , { details =true } )[ 3 ]. end_col ) 1972-- mark is not removed when deleting bytes from the end of the range 1973feed ( 'lx' ) 1974eq ( 1 , get_extmark_by_id ( ns , 3 , { details =true } )[ 3 ]. end_col ) 1975-- mark is not removed when deleting bytes beyond end of the range 1976feed ( 'x' ) 1977eq ( 1 , get_extmark_by_id ( ns , 3 , { details =true } )[ 3 ]. end_col ) 1978-- mark is removed when all bytes in the range are deleted 1979feed ( 'hx' ) 1980eq ( true , get_extmark_by_id ( ns , 3 , { details =true } )[ 3 ]. invalid ) 1981-- mark is restored with undo_restore == true if pos did not change 1982command ( 'undo' ) 1983eq ( nil , get_extmark_by_id ( ns , 3 , { details =true } )[ 3 ]. invalid ) 1984-- multiline mark is not removed when start of its range is deleted 1985set_extmark ( ns , 4 , 1 , 4 , { 1986undo_restore =false , 1987invalidate =true , 1988hl_group ='Error' , 1989end_col =7 , 1990end_row =3 , 1991} ) 1992feed ( 'ddDdd' ) 1993eq ( { 0 , 0 } , get_extmark_by_id ( ns , 4 , {} )) 1994-- multiline mark is removed when entirety of its range is deleted 1995feed ( 'vj2ed' ) 1996eq ( {} , get_extmark_by_id ( ns , 4 , {} )) 1997end ) 1998 1999it ( 'no crash checking invalidated flag of sign pair end key #31856' , function () 2000api . nvim_buf_set_lines ( 0 , 0 , 1 , false , { '' , '' } ) 2001api . nvim_set_option_value ( 'signcolumn' , 'auto:2' , {} ) 2002set_extmark ( ns , 1 , 0 , 0 , { sign_text ='S1' , invalidate =true , end_row =0 } ) 2003set_extmark ( ns , 2 , 1 , 0 , { sign_text ='S2' , end_row =1 } ) 2004command ( 'd' ) 2005api . nvim_buf_clear_namespace ( 0 , ns , 0 , - 1 ) 2006n . assert_alive () 2007end ) 2008 2009it ( 'can set a URL' , function () 2010local url1 ='https://example.com' 2011local url2 ='http://127.0.0.1' 2012set_extmark ( ns , 1 , 0 , 0 , { url =url1 , end_col =3 } ) 2013set_extmark ( ns , 2 , 0 , 3 , { url =url2 , hl_group ='Search' , end_col =5 } ) 2014local extmarks =get_extmarks ( ns , 0 , - 1 , { details =true } ) 2015eq ( 2 , # extmarks ) 2016eq ( url1 , extmarks [ 1 ][ 4 ]. url ) 2017eq ( url2 , extmarks [ 2 ][ 4 ]. url ) 2018eq ( 'Search' , extmarks [ 2 ][ 4 ]. hl_group ) 2019end ) 2020 2021it ( 'respects priority' , function () 2022screen =Screen . new ( 15 , 10 ) 2023 2024set_extmark ( ns , marks [ 1 ], 0 , 0 , { 2025hl_group ='Comment' , 2026end_col =2 , 2027priority =20 , 2028} ) 2029 2030-- Extmark defined after first extmark but has lower priority, first extmark "wins" 2031set_extmark ( ns , marks [ 2 ], 0 , 0 , { 2032hl_group ='String' , 2033end_col =2 , 2034priority =10 , 2035} ) 2036 2037screen : expect { 2038grid =[[ 2039{1:12}34^5 | 2040{2:~ }|*8 2041| 2042]] , 2043attr_ids ={ 2044[ 1 ] ={ foreground =Screen . colors . Blue1 } , 2045[ 2 ] ={ foreground =Screen . colors . Blue1 , bold =true } , 2046} , 2047} 2048end ) 2049 2050it ( 'are invalidated when "nofile" buffer is unloaded' , function () 2051local buf =api . nvim_create_buf ( false , true ) 2052api . nvim_buf_set_name ( buf , 'foo' ) 2053api . nvim_buf_set_lines ( buf , 0 , 0 , false , { 'foo' , 'bar' } ) 2054local id =api . nvim_buf_set_extmark ( buf , ns , 1 , 0 , { invalidate =true } ) 2055api . nvim_buf_delete ( buf , { unload =true } ) 2056local mark ={ 0 , 0 , { invalid =true , invalidate =true , ns_id =ns , right_gravity =true } } 2057eq ( mark , api . nvim_buf_get_extmark_by_id ( buf , ns , id , { details =true } )) 2058end ) 2059end ) 2060 2061describe ( 'Extmarks buffer api with many marks' , function () 2062local ns1 2063local ns2 2064local ns_marks ={} 2065before_each ( function () 2066clear () 2067ns1 =request ( 'nvim_create_namespace' , 'ns1' ) 2068ns2 =request ( 'nvim_create_namespace' , 'ns2' ) 2069ns_marks ={ [ ns1 ] ={} , [ ns2 ] ={} } 2070local lines ={} 2071for i =1 , 30 do 2072lines [ # lines + 1 ] =string . rep ( 'x ' , i ) 2073end 2074api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , lines ) 2075local ns =ns1 2076local q =0 2077for i =0 , 29 do 2078for j =0 , i do 2079local id =set_extmark ( ns , 0 , i , j ) 2080eq ( nil , ns_marks [ ns ][ id ]) 2081ok ( id > 0 ) 2082ns_marks [ ns ][ id ] ={ i , j } 2083ns =ns1 + ns2 - ns 2084q =q + 1 2085end 2086end 2087eq ( 233 , # ns_marks [ ns1 ]) 2088eq ( 232 , # ns_marks [ ns2 ]) 2089end ) 2090 2091local function get_marks ( ns ) 2092local mark_list =get_extmarks ( ns , 0 , - 1 ) 2093local marks ={} 2094for _ , mark in ipairs ( mark_list ) do 2095local id , row , col =unpack ( mark ) 2096eq ( nil , marks [ id ], 'duplicate mark' ) 2097marks [ id ] ={ row , col } 2098end 2099return marks 2100end 2101 2102it ( 'can get marks' , function () 2103eq ( ns_marks [ ns1 ], get_marks ( ns1 )) 2104eq ( ns_marks [ ns2 ], get_marks ( ns2 )) 2105end ) 2106 2107it ( 'can clear all marks in ns' , function () 2108api . nvim_buf_clear_namespace ( 0 , ns1 , 0 , - 1 ) 2109eq ( {} , get_marks ( ns1 )) 2110eq ( ns_marks [ ns2 ], get_marks ( ns2 )) 2111api . nvim_buf_clear_namespace ( 0 , ns2 , 0 , - 1 ) 2112eq ( {} , get_marks ( ns1 )) 2113eq ( {} , get_marks ( ns2 )) 2114end ) 2115 2116it ( 'can clear line range' , function () 2117api . nvim_buf_clear_namespace ( 0 , ns1 , 10 , 20 ) 2118for id , mark in pairs ( ns_marks [ ns1 ]) do 2119if 10 <= mark [ 1 ] and mark [ 1 ] < 20 then 2120ns_marks [ ns1 ][ id ] =nil 2121end 2122end 2123eq ( ns_marks [ ns1 ], get_marks ( ns1 )) 2124eq ( ns_marks [ ns2 ], get_marks ( ns2 )) 2125 2126api . nvim_buf_clear_namespace ( 0 , ns1 , 0 , 10 ) 2127for id , mark in pairs ( ns_marks [ ns1 ]) do 2128if mark [ 1 ] < 10 then 2129ns_marks [ ns1 ][ id ] =nil 2130end 2131end 2132eq ( ns_marks [ ns1 ], get_marks ( ns1 )) 2133eq ( ns_marks [ ns2 ], get_marks ( ns2 )) 2134 2135api . nvim_buf_clear_namespace ( 0 , ns1 , 20 , - 1 ) 2136for id , mark in pairs ( ns_marks [ ns1 ]) do 2137if mark [ 1 ] >= 20 then 2138ns_marks [ ns1 ][ id ] =nil 2139end 2140end 2141eq ( ns_marks [ ns1 ], get_marks ( ns1 )) 2142eq ( ns_marks [ ns2 ], get_marks ( ns2 )) 2143end ) 2144 2145it ( 'can delete line' , function () 2146feed ( '10Gdd' ) 2147for _ , marks in pairs ( ns_marks ) do 2148for id , mark in pairs ( marks ) do 2149if mark [ 1 ] == 9 then 2150marks [ id ] ={ 9 , 0 } 2151elseif mark [ 1 ] >= 10 then 2152mark [ 1 ] =mark [ 1 ] - 1 2153end 2154end 2155end 2156eq ( ns_marks [ ns1 ], get_marks ( ns1 )) 2157eq ( ns_marks [ ns2 ], get_marks ( ns2 )) 2158end ) 2159 2160it ( 'can delete lines' , function () 2161feed ( '10G10dd' ) 2162for _ , marks in pairs ( ns_marks ) do 2163for id , mark in pairs ( marks ) do 2164if 9 <= mark [ 1 ] and mark [ 1 ] < 19 then 2165marks [ id ] ={ 9 , 0 } 2166elseif mark [ 1 ] >= 19 then 2167mark [ 1 ] =mark [ 1 ] - 10 2168end 2169end 2170end 2171eq ( ns_marks [ ns1 ], get_marks ( ns1 )) 2172eq ( ns_marks [ ns2 ], get_marks ( ns2 )) 2173end ) 2174 2175it ( 'can wipe buffer' , function () 2176command ( 'bwipe!' ) 2177eq ( {} , get_marks ( ns1 )) 2178eq ( {} , get_marks ( ns2 )) 2179end ) 2180end ) 2181 2182describe ( 'API/win_extmark' , function () 2183local screen 2184local marks , line1 , line2 2185local ns 2186 2187before_each ( function () 2188-- Initialize some namespaces and insert text into a buffer 2189marks ={ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } 2190 2191line1 ='non ui-watched line' 2192line2 ='ui-watched line' 2193 2194clear () 2195 2196insert ( line1 ) 2197feed ( 'o<esc>' ) 2198insert ( line2 ) 2199ns =request ( 'nvim_create_namespace' , 'extmark-ui' ) 2200end ) 2201 2202it ( 'sends and only sends ui-watched marks to ui' , function () 2203screen =Screen . new ( 20 , 4 ) 2204-- should send this 2205set_extmark ( ns , marks [ 1 ], 1 , 0 , { ui_watched =true } ) 2206-- should not send this 2207set_extmark ( ns , marks [ 2 ], 0 , 0 , { ui_watched =false } ) 2208screen : expect ( { 2209grid =[[ 2210non ui-watched line | 2211ui-watched lin^e | 2212{1:~ }| 2213| 2214]] , 2215extmarks ={ 2216[ 2 ] ={ 2217-- positioned at the end of the 2nd line 2218{ 1000 , ns , marks [ 1 ], 1 , 16 } , 2219} , 2220} , 2221} ) 2222end ) 2223 2224it ( 'sends multiple ui-watched marks to ui' , function () 2225screen =Screen . new ( 20 , 4 ) 2226feed ( '15A!<Esc>' ) 2227-- should send all of these 2228set_extmark ( ns , marks [ 1 ], 1 , 0 , { ui_watched =true , virt_text_pos ='overlay' } ) 2229set_extmark ( ns , marks [ 2 ], 1 , 2 , { ui_watched =true , virt_text_pos ='overlay' } ) 2230set_extmark ( ns , marks [ 3 ], 1 , 4 , { ui_watched =true , virt_text_pos ='overlay' } ) 2231set_extmark ( ns , marks [ 4 ], 1 , 6 , { ui_watched =true , virt_text_pos ='overlay' } ) 2232set_extmark ( ns , marks [ 5 ], 1 , 8 , { ui_watched =true } ) 2233screen : expect ( { 2234grid =[[ 2235non ui-watched line | 2236ui-watched line!!!!!| 2237!!!!!!!!!^! | 2238| 2239]] , 2240extmarks ={ 2241[ 2 ] ={ 2242-- notification from 1st call 2243{ 1000 , ns , marks [ 1 ], 1 , 0 } , 2244-- notifications from 2nd call 2245{ 1000 , ns , marks [ 1 ], 1 , 0 } , 2246{ 1000 , ns , marks [ 2 ], 1 , 2 } , 2247-- notifications from 3rd call 2248{ 1000 , ns , marks [ 1 ], 1 , 0 } , 2249{ 1000 , ns , marks [ 2 ], 1 , 2 } , 2250{ 1000 , ns , marks [ 3 ], 1 , 4 } , 2251-- notifications from 4th call 2252{ 1000 , ns , marks [ 1 ], 1 , 0 } , 2253{ 1000 , ns , marks [ 2 ], 1 , 2 } , 2254{ 1000 , ns , marks [ 3 ], 1 , 4 } , 2255{ 1000 , ns , marks [ 4 ], 1 , 6 } , 2256-- final 2257-- overlay 2258{ 1000 , ns , marks [ 1 ], 1 , 0 } , 2259{ 1000 , ns , marks [ 2 ], 1 , 2 } , 2260{ 1000 , ns , marks [ 3 ], 1 , 4 } , 2261{ 1000 , ns , marks [ 4 ], 1 , 6 } , 2262-- eol 2263{ 1000 , ns , marks [ 5 ], 2 , 11 } , 2264} , 2265} , 2266} ) 2267end ) 2268 2269it ( 'updates ui-watched marks' , function () 2270screen =Screen . new ( 20 , 4 ) 2271-- should send this 2272set_extmark ( ns , marks [ 1 ], 1 , 0 , { ui_watched =true } ) 2273-- should not send this 2274set_extmark ( ns , marks [ 2 ], 0 , 0 , { ui_watched =false } ) 2275-- make some changes 2276insert ( ' update' ) 2277screen : expect ( { 2278grid =[[ 2279non ui-watched line | 2280ui-watched linupdat^e| 2281e | 2282| 2283]] , 2284extmarks ={ 2285[ 2 ] ={ 2286-- positioned at the end of the 2nd line 2287{ 1000 , ns , marks [ 1 ], 1 , 16 } , 2288-- updated and wrapped to 3rd line 2289{ 1000 , ns , marks [ 1 ], 2 , 2 } , 2290} , 2291} , 2292} ) 2293feed ( '<c-e>' ) 2294screen : expect ( { 2295grid =[[ 2296ui-watched linupdat^e| 2297e | 2298{1:~ }| 2299| 2300]] , 2301extmarks ={ 2302[ 2 ] ={ 2303-- positioned at the end of the 2nd line 2304{ 1000 , ns , marks [ 1 ], 1 , 16 } , 2305-- updated and wrapped to 3rd line 2306{ 1000 , ns , marks [ 1 ], 2 , 2 } , 2307-- scrolled up one line, should be handled by grid scroll 2308} , 2309} , 2310} ) 2311end ) 2312 2313it ( 'sends ui-watched to splits' , function () 2314screen =Screen . new ( 20 , 8 , { ext_multigrid =true } ) 2315-- should send this 2316set_extmark ( ns , marks [ 1 ], 1 , 0 , { ui_watched =true } ) 2317-- should not send this 2318set_extmark ( ns , marks [ 2 ], 0 , 0 , { ui_watched =false } ) 2319command ( 'split' ) 2320screen : expect ( { 2321grid =[[ 2322## grid 1 2323[4:--------------------]|*3 2324{3:[No Name] [+] }| 2325[2:--------------------]|*2 2326{2:[No Name] [+] }| 2327[3:--------------------]| 2328## grid 2 2329non ui-watched line | 2330ui-watched line | 2331## grid 3 2332| 2333## grid 4 2334non ui-watched line | 2335ui-watched lin^e | 2336{1:~ }| 2337]] , 2338extmarks ={ 2339[ 2 ] ={ 2340-- positioned at the end of the 2nd line 2341{ 1000 , ns , marks [ 1 ], 1 , 16 } , 2342-- updated after split 2343{ 1000 , ns , marks [ 1 ], 1 , 16 } , 2344} , 2345[ 4 ] ={ 2346-- only after split 2347{ 1001 , ns , marks [ 1 ], 1 , 16 } , 2348} , 2349} , 2350} ) 2351-- make some changes 2352insert ( ' update' ) 2353screen : expect ( { 2354grid =[[ 2355## grid 1 2356[4:--------------------]|*3 2357{3:[No Name] [+] }| 2358[2:--------------------]|*2 2359{2:[No Name] [+] }| 2360[3:--------------------]| 2361## grid 2 2362non ui-watched line | 2363ui-watched linupd{1:@@@}| 2364## grid 3 2365| 2366## grid 4 2367non ui-watched line | 2368ui-watched linupdat^e| 2369e | 2370]] , 2371extmarks ={ 2372[ 2 ] ={ 2373-- positioned at the end of the 2nd line 2374{ 1000 , ns , marks [ 1 ], 1 , 16 } , 2375-- updated after split 2376{ 1000 , ns , marks [ 1 ], 1 , 16 } , 2377} , 2378[ 4 ] ={ 2379{ 1001 , ns , marks [ 1 ], 1 , 16 } , 2380-- updated 2381{ 1001 , ns , marks [ 1 ], 2 , 2 } , 2382} , 2383} , 2384} ) 2385end ) 2386end )