mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	vim-patch:9.0.1443: ending Insert mode when accessing a hidden prompt buffer (#22984)
Problem:    Ending Insert mode when accessing a hidden prompt buffer.
Solution:   Don't stop Insert mode when it was active before. (closes vim/vim#12237)
05a627c3d4
Co-authored-by: Bram Moolenaar <Bram@vim.org>
			
			
This commit is contained in:
		@@ -1421,6 +1421,8 @@ void aucmd_prepbuf(aco_save_T *aco, buf_T *buf)
 | 
				
			|||||||
  aco->save_curwin_handle = curwin->handle;
 | 
					  aco->save_curwin_handle = curwin->handle;
 | 
				
			||||||
  aco->save_curbuf = curbuf;
 | 
					  aco->save_curbuf = curbuf;
 | 
				
			||||||
  aco->save_prevwin_handle = prevwin == NULL ? 0 : prevwin->handle;
 | 
					  aco->save_prevwin_handle = prevwin == NULL ? 0 : prevwin->handle;
 | 
				
			||||||
 | 
					  aco->save_State = State;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (win != NULL) {
 | 
					  if (win != NULL) {
 | 
				
			||||||
    // There is a window for "buf" in the current tab page, make it the
 | 
					    // There is a window for "buf" in the current tab page, make it the
 | 
				
			||||||
    // curwin.  This is preferred, it has the least side effects (esp. if
 | 
					    // curwin.  This is preferred, it has the least side effects (esp. if
 | 
				
			||||||
@@ -1497,6 +1499,10 @@ void aucmd_restbuf(aco_save_T *aco)
 | 
				
			|||||||
win_found:
 | 
					win_found:
 | 
				
			||||||
    // May need to stop Insert mode if we were in a prompt buffer.
 | 
					    // May need to stop Insert mode if we were in a prompt buffer.
 | 
				
			||||||
    leaving_window(curwin);
 | 
					    leaving_window(curwin);
 | 
				
			||||||
 | 
					    // Do not stop Insert mode when already in Insert mode before.
 | 
				
			||||||
 | 
					    if (aco->save_State & MODE_INSERT) {
 | 
				
			||||||
 | 
					      stop_insert_mode = false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    // Remove the window.
 | 
					    // Remove the window.
 | 
				
			||||||
    win_remove(curwin, NULL);
 | 
					    win_remove(curwin, NULL);
 | 
				
			||||||
    pmap_del(handle_T)(&window_handles, curwin->handle);
 | 
					    pmap_del(handle_T)(&window_handles, curwin->handle);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,7 @@ typedef struct {
 | 
				
			|||||||
  bufref_T new_curbuf;            ///< new curbuf
 | 
					  bufref_T new_curbuf;            ///< new curbuf
 | 
				
			||||||
  char *globaldir;                ///< saved value of globaldir
 | 
					  char *globaldir;                ///< saved value of globaldir
 | 
				
			||||||
  bool save_VIsual_active;        ///< saved VIsual_active
 | 
					  bool save_VIsual_active;        ///< saved VIsual_active
 | 
				
			||||||
 | 
					  int save_State;                 ///< saved State
 | 
				
			||||||
} aco_save_T;
 | 
					} aco_save_T;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct AutoCmd_S AutoCmd;
 | 
					typedef struct AutoCmd_S AutoCmd;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -247,6 +247,7 @@ describe('prompt buffer', function()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      func DoAppend()
 | 
					      func DoAppend()
 | 
				
			||||||
        call appendbufline('prompt', '$', 'Test')
 | 
					        call appendbufline('prompt', '$', 'Test')
 | 
				
			||||||
 | 
					        return ''
 | 
				
			||||||
      endfunc
 | 
					      endfunc
 | 
				
			||||||
    ]])
 | 
					    ]])
 | 
				
			||||||
    feed('asomething<CR>')
 | 
					    feed('asomething<CR>')
 | 
				
			||||||
@@ -254,7 +255,12 @@ describe('prompt buffer', function()
 | 
				
			|||||||
    neq(prev_win, meths.get_current_win())
 | 
					    neq(prev_win, meths.get_current_win())
 | 
				
			||||||
    feed('exit<CR>')
 | 
					    feed('exit<CR>')
 | 
				
			||||||
    eq(prev_win, meths.get_current_win())
 | 
					    eq(prev_win, meths.get_current_win())
 | 
				
			||||||
 | 
					    eq({ mode = 'n', blocking = false }, meths.get_mode())
 | 
				
			||||||
    command('call DoAppend()')
 | 
					    command('call DoAppend()')
 | 
				
			||||||
    eq({ mode = 'n', blocking = false }, meths.get_mode())
 | 
					    eq({ mode = 'n', blocking = false }, meths.get_mode())
 | 
				
			||||||
 | 
					    feed('i')
 | 
				
			||||||
 | 
					    eq({ mode = 'i', blocking = false }, meths.get_mode())
 | 
				
			||||||
 | 
					    command('call DoAppend()')
 | 
				
			||||||
 | 
					    eq({ mode = 'i', blocking = false }, meths.get_mode())
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
end)
 | 
					end)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -271,6 +271,7 @@ func Test_prompt_appending_while_hidden()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      func DoAppend()
 | 
					      func DoAppend()
 | 
				
			||||||
        call appendbufline('prompt', '$', 'Test')
 | 
					        call appendbufline('prompt', '$', 'Test')
 | 
				
			||||||
 | 
					        return ''
 | 
				
			||||||
      endfunc
 | 
					      endfunc
 | 
				
			||||||
  END
 | 
					  END
 | 
				
			||||||
  call writefile(script, 'XpromptBuffer', 'D')
 | 
					  call writefile(script, 'XpromptBuffer', 'D')
 | 
				
			||||||
@@ -283,11 +284,21 @@ func Test_prompt_appending_while_hidden()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  call term_sendkeys(buf, "exit\<CR>")
 | 
					  call term_sendkeys(buf, "exit\<CR>")
 | 
				
			||||||
  call TermWait(buf)
 | 
					  call TermWait(buf)
 | 
				
			||||||
 | 
					  call assert_notmatch('-- INSERT --', term_getline(buf, 10))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  call term_sendkeys(buf, ":call DoAppend()\<CR>")
 | 
					  call term_sendkeys(buf, ":call DoAppend()\<CR>")
 | 
				
			||||||
  call TermWait(buf)
 | 
					  call TermWait(buf)
 | 
				
			||||||
  call assert_notmatch('-- INSERT --', term_getline(buf, 10))
 | 
					  call assert_notmatch('-- INSERT --', term_getline(buf, 10))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  call term_sendkeys(buf, "i")
 | 
				
			||||||
 | 
					  call TermWait(buf)
 | 
				
			||||||
 | 
					  call assert_match('-- INSERT --', term_getline(buf, 10))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  call term_sendkeys(buf, "\<C-R>=DoAppend()\<CR>")
 | 
				
			||||||
 | 
					  call TermWait(buf)
 | 
				
			||||||
 | 
					  call assert_match('-- INSERT --', term_getline(buf, 10))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  call term_sendkeys(buf, "\<Esc>")
 | 
				
			||||||
  call StopVimInTerminal(buf)
 | 
					  call StopVimInTerminal(buf)
 | 
				
			||||||
endfunc
 | 
					endfunc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user