diff src/edit.c @ 14037:afce2005fdc8 v8.1.0036

patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse commit https://github.com/vim/vim/commit/891e1fd894720d0b99a9daefa41e8181844f819a Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 6 18:02:39 2018 +0200 patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse Problem: Not restoring Insert mode if leaving a prompt buffer by using a mouse click. Solution: Set b_prompt_insert appropriately. Also correct cursor position when moving cursor to last line.
author Christian Brabandt <cb@256bit.org>
date Wed, 06 Jun 2018 18:15:05 +0200
parents bccd66fa00c1
children e182079c3374
line wrap: on
line diff
--- a/src/edit.c
+++ b/src/edit.c
@@ -1411,11 +1411,10 @@ doESCkey:
 #ifdef FEAT_JOB_CHANNEL
 	    if (bt_prompt(curbuf))
 	    {
-		buf_T *buf = curbuf;
-
 		invoke_prompt_callback();
-		if (curbuf != buf)
-		    // buffer changed, get out of Insert mode
+		if (!bt_prompt(curbuf))
+		    // buffer changed to a non-prompt buffer, get out of
+		    // Insert mode
 		    goto doESCkey;
 		break;
 	    }
@@ -1906,6 +1905,8 @@ init_prompt(int cmdchar_todo)
 	coladvance((colnr_T)MAXCOL);
     if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt))
 	curwin->w_cursor.col = STRLEN(prompt);
+    /* Make sure the cursor is in a valid position. */
+    check_cursor();
 }
 
 /*
@@ -9467,7 +9468,7 @@ ins_bs(
 
     /* If deleted before the insertion point, adjust it */
     if (curwin->w_cursor.lnum == Insstart_orig.lnum
-				       && curwin->w_cursor.col < Insstart_orig.col)
+				  && curwin->w_cursor.col < Insstart_orig.col)
 	Insstart_orig.col = curwin->w_cursor.col;
 
     /* vi behaviour: the cursor moves backward but the character that
@@ -9517,6 +9518,11 @@ ins_mouse(int c)
 	     * previous one to stop insert there properly. */
 	    curwin = old_curwin;
 	    curbuf = curwin->w_buffer;
+#ifdef FEAT_JOB_CHANNEL
+	    if (bt_prompt(curbuf))
+		// Restart Insert mode when re-entering the prompt buffer.
+		curbuf->b_prompt_insert = 'A';
+#endif
 	}
 	start_arrow(curwin == old_curwin ? &tpos : NULL);
 	if (curwin != new_curwin && win_valid(new_curwin))