# HG changeset patch # User Christian Brabandt # Date 1708025404 -3600 # Node ID 3b654f4462c51e1737b48fb73401f60b21b832c8 # Parent 5904297858aabd90793b17ec2bdf16ed5ee4db9c patch 9.1.0112: Remove undo information, when cleaning quickfix buffer Commit: https://github.com/vim/vim/commit/f0d3d4a42657dca996e790aa829de3c6be7fdb63 Author: Christian Brabandt Date: Thu Feb 15 20:15:04 2024 +0100 patch 9.1.0112: Remove undo information, when cleaning quickfix buffer Problem: When the quickfix buffer has been modified an autocommand may invalidate the undo stack (kawarimidoll) Solution: When clearing the quickfix buffer, also wipe the undo stack fixes: #13905 closes: #13928 Signed-off-by: Christian Brabandt diff --git a/src/quickfix.c b/src/quickfix.c --- a/src/quickfix.c +++ b/src/quickfix.c @@ -4829,8 +4829,18 @@ qf_fill_buffer(qf_list_T *qfl, buf_T *bu } // delete all existing lines + // + // Note: we cannot store undo information, because + // qf buffer is usually not allowed to be modified. + // + // So we need to clean up undo information + // otherwise autocommands may invalidate the undo stack while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) (void)ml_delete((linenr_T)1); + + // Remove all undo information + u_blockfree(curbuf); + u_clearall(curbuf); } // Check if there is anything to display diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -4413,4 +4413,32 @@ func Test_autocmd_shortmess() delfunc SetupVimTest_shm endfunc +func Test_autocmd_invalidates_undo_on_textchanged() + CheckRunVimInTerminal + let script =<< trim END + set hidden + " create quickfix list (at least 2 lines to move line) + vimgrep /u/j % + + " enter quickfix window + cwindow + + " set modifiable + setlocal modifiable + + " set autocmd to clear quickfix list + + autocmd! TextChanged call setqflist([]) + " move line + move+1 + END + call writefile(script, 'XTest_autocmd_invalidates_undo_on_textchanged', 'D') + let buf = RunVimInTerminal('XTest_autocmd_invalidates_undo_on_textchanged', {'rows': 20}) + call term_sendkeys(buf, ":so %\") + call term_sendkeys(buf, "G") + call WaitForAssert({-> assert_match('^XTest_autocmd_invalidates_undo_on_textchanged\s*$', term_getline(buf, 20))}, 1000) + + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 112, +/**/ 111, /**/ 110,