comparison src/testdir/test_autocmd.vim @ 14463:3b87daa5c37a v8.1.0245

patch 8.1.0245: calling setline() in TextChangedI autocmd breaks undo commit https://github.com/vim/vim/commit/91d2e783b41ca900bc603b3cb5e083c8a4a33170 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 7 19:05:01 2018 +0200 patch 8.1.0245: calling setline() in TextChangedI autocmd breaks undo Problem: Calling setline() in TextChangedI autocmd breaks undo. (Jason Felice) Solution: Don't save lines for undo when already saved. (closes #3291)
author Christian Brabandt <cb@256bit.org>
date Tue, 07 Aug 2018 19:15:05 +0200
parents 415185e2c970
children c71d65c3672f
comparison
equal deleted inserted replaced
14462:1b1e12886c9e 14463:3b87daa5c37a
585 call assert_equal(g:opt[0], g:opt[1]) 585 call assert_equal(g:opt[0], g:opt[1])
586 586
587 " Cleanup 587 " Cleanup
588 au! OptionSet 588 au! OptionSet
589 for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp'] 589 for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp']
590 exe printf(":set %s&vi", opt) 590 exe printf(":set %s&vim", opt)
591 endfor 591 endfor
592 call test_override('starting', 0) 592 call test_override('starting', 0)
593 delfunc! AutoCommandOptionSet 593 delfunc! AutoCommandOptionSet
594 endfunc 594 endfunc
595 595
1311 set complete&vim completeopt&vim 1311 set complete&vim completeopt&vim
1312 1312
1313 bw! 1313 bw!
1314 endfunc 1314 endfunc
1315 1315
1316 let g:setline_handled = v:false
1317 func! SetLineOne()
1318 if !g:setline_handled
1319 call setline(1, "(x)")
1320 let g:setline_handled = v:true
1321 endif
1322 endfunc
1323
1324 func Test_TextChangedI_with_setline()
1325 new
1326 call test_override('char_avail', 1)
1327 autocmd TextChangedI <buffer> call SetLineOne()
1328 call feedkeys("i(\<CR>\<Esc>", 'tx')
1329 call assert_equal('(', getline(1))
1330 call assert_equal('x)', getline(2))
1331 undo
1332 call assert_equal('(', getline(1))
1333 call assert_equal('', getline(2))
1334 undo
1335 call assert_equal('', getline(1))
1336
1337 call test_override('starting', 0)
1338 bwipe!
1339 endfunc
1340
1316 func Test_Changed_FirstTime() 1341 func Test_Changed_FirstTime()
1317 if !has('terminal') || has('gui_running') 1342 if !has('terminal') || has('gui_running')
1318 return 1343 return
1319 endif 1344 endif
1320 " Prepare file for TextChanged event. 1345 " Prepare file for TextChanged event.