mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	vim-patch:9.1.1337: Undo corrupted with 'completeopt' "preinsert" when switching buffer (#33600)
Problem:  Undo corrupted with 'completeopt' "preinsert" when switching
          buffer or window.
Solution: Do not delete preinsert text when switching buffer or window.
          (zeertzjq)
related: neovim/neovim#33581
closes: vim/vim#17193
1343681aba
			
			
This commit is contained in:
		@@ -2334,9 +2334,10 @@ static bool set_ctrl_x_mode(const int c)
 | 
			
		||||
static bool ins_compl_stop(const int c, const int prev_mode, bool retval)
 | 
			
		||||
{
 | 
			
		||||
  // Remove pre-inserted text when present.
 | 
			
		||||
  if (ins_compl_preinsert_effect()) {
 | 
			
		||||
  if (ins_compl_preinsert_effect() && ins_compl_win_active(curwin)) {
 | 
			
		||||
    ins_compl_delete(false);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Get here when we have finished typing a sequence of ^N and
 | 
			
		||||
  // ^P or other completion characters in CTRL-X mode.  Free up
 | 
			
		||||
  // memory that was used, and make sure we can redo the insert.
 | 
			
		||||
 
 | 
			
		||||
@@ -3223,7 +3223,7 @@ func Test_complete_info_completed()
 | 
			
		||||
  set cot&
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
function Test_completeopt_preinsert()
 | 
			
		||||
func Test_completeopt_preinsert()
 | 
			
		||||
  func Omni_test(findstart, base)
 | 
			
		||||
    if a:findstart
 | 
			
		||||
      return col(".")
 | 
			
		||||
@@ -3363,6 +3363,47 @@ function Test_completeopt_preinsert()
 | 
			
		||||
  call assert_equal(4, g:col)
 | 
			
		||||
  call assert_equal("wp.", getline('.'))
 | 
			
		||||
 | 
			
		||||
  %delete _
 | 
			
		||||
  let &l:undolevels = &l:undolevels
 | 
			
		||||
  normal! ifoo
 | 
			
		||||
  let &l:undolevels = &l:undolevels
 | 
			
		||||
  normal! obar
 | 
			
		||||
  let &l:undolevels = &l:undolevels
 | 
			
		||||
  normal! obaz
 | 
			
		||||
  let &l:undolevels = &l:undolevels
 | 
			
		||||
 | 
			
		||||
  func CheckUndo()
 | 
			
		||||
    let g:errmsg = ''
 | 
			
		||||
    call assert_equal(['foo', 'bar', 'baz'], getline(1, '$'))
 | 
			
		||||
    undo
 | 
			
		||||
    call assert_equal(['foo', 'bar'], getline(1, '$'))
 | 
			
		||||
    undo
 | 
			
		||||
    call assert_equal(['foo'], getline(1, '$'))
 | 
			
		||||
    undo
 | 
			
		||||
    call assert_equal([''], getline(1, '$'))
 | 
			
		||||
    later 3
 | 
			
		||||
    call assert_equal(['foo', 'bar', 'baz'], getline(1, '$'))
 | 
			
		||||
    call assert_equal('', v:errmsg)
 | 
			
		||||
  endfunc
 | 
			
		||||
 | 
			
		||||
  " Check that switching buffer with "preinsert" doesn't corrupt undo.
 | 
			
		||||
  new
 | 
			
		||||
  setlocal bufhidden=wipe
 | 
			
		||||
  inoremap <buffer> <F2> <Cmd>enew!<CR>
 | 
			
		||||
  call feedkeys("i\<C-X>\<C-O>\<F2>\<Esc>", 'tx')
 | 
			
		||||
  bwipe!
 | 
			
		||||
  call CheckUndo()
 | 
			
		||||
 | 
			
		||||
  " Check that closing window with "preinsert" doesn't corrupt undo.
 | 
			
		||||
  new
 | 
			
		||||
  setlocal bufhidden=wipe
 | 
			
		||||
  inoremap <buffer> <F2> <Cmd>close!<CR>
 | 
			
		||||
  call feedkeys("i\<C-X>\<C-O>\<F2>\<Esc>", 'tx')
 | 
			
		||||
  call CheckUndo()
 | 
			
		||||
 | 
			
		||||
  %delete _
 | 
			
		||||
  delfunc CheckUndo
 | 
			
		||||
 | 
			
		||||
  bw!
 | 
			
		||||
  set cot&
 | 
			
		||||
  set omnifunc&
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user