patch 9.1.1295: clientserver: does not handle :stopinsert correctly

Problem:  clientserver: When in insert mode, a :stopinsert command
          is not correctly processed (user202729)
Solution: If the :stopinsert command is received while waiting for
          input, stuff the NOP key into the type-ahead buffer and
          detect that :stopinsert was used in edit() so that the
          cursor position is decremented.

fixes: #17016
closes: #17024

Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/edit.c b/src/edit.c
index 53428e0..ab67fdc 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -608,7 +608,16 @@
 		    if (c != K_IGNORE && c != K_NOP)
 			vungetc(c);
 		    count = 0;
-		    nomove = TRUE;
+
+		    if (!bt_prompt(curwin->w_buffer)
+#ifdef FEAT_TERMINAL
+			    && !bt_terminal(curwin->w_buffer)
+#endif
+			    && stop_insert_mode)
+			// :stopinsert command via callback or via server command
+			nomove = FALSE;
+		    else
+			nomove = TRUE;
 		    ins_compl_prep(ESC);
 		    goto doESCkey;
 		}