aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2019-05-23 05:15:04 +0900
committererw7 <erw7.github@gmail.com>2020-02-12 15:16:32 +0900
commit783aecd501de2719f3059252e8444ef00c7c3d4a (patch)
tree22d5767893e21a5c1a092b41d75a0c4952932d33
parent3ca0343fb99b7f7412fca73be6f94df252b6f0a3 (diff)
downloadrneovim-783aecd501de2719f3059252e8444ef00c7c3d4a.tar.gz
rneovim-783aecd501de2719f3059252e8444ef00c7c3d4a.tar.bz2
rneovim-783aecd501de2719f3059252e8444ef00c7c3d4a.zip
vim-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. https://github.com/vim/vim/commit/891e1fd894720d0b99a9daefa41e8181844f819a
-rw-r--r--src/nvim/buffer.c3
-rw-r--r--src/nvim/edit.c15
-rw-r--r--test/functional/legacy/prompt_buffer_spec.lua12
3 files changed, 20 insertions, 10 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 91a96d1195..a9b37af917 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -5293,6 +5293,9 @@ char_u *buf_spname(buf_T *buf)
if (buf->b_fname != NULL) {
return buf->b_fname;
}
+ if (bt_prompt(buf)) {
+ return (char_u *)_("[Prompt]");
+ }
return (char_u *)_("[Scratch]");
}
if (buf->b_fname == NULL) {
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 64510589fd..40d34bd0b7 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1151,8 +1151,9 @@ check_pum:
}
if (bt_prompt(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
return 0;
}
break;
@@ -1618,6 +1619,8 @@ static void init_prompt(int cmdchar_todo)
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();
}
// Return TRUE if the cursor is in the editable position of the prompt line.
@@ -8219,10 +8222,14 @@ static void ins_mouse(int c)
win_T *new_curwin = curwin;
if (curwin != old_curwin && win_valid(old_curwin)) {
- /* Mouse took us to another window. We need to go back to the
- * previous one to stop insert there properly. */
+ // Mouse took us to another window. We need to go back to the
+ // previous one to stop insert there properly.
curwin = old_curwin;
curbuf = curwin->w_buffer;
+ if (bt_prompt(curbuf)) {
+ // Restart Insert mode when re-entering the prompt buffer.
+ curbuf->b_prompt_insert = 'A';
+ }
}
start_arrow(curwin == old_curwin ? &tpos : NULL);
if (curwin != new_curwin && win_valid(new_curwin)) {
diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua
index d494bb5a81..d5b315a0c7 100644
--- a/test/functional/legacy/prompt_buffer_spec.lua
+++ b/test/functional/legacy/prompt_buffer_spec.lua
@@ -45,7 +45,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- [Scratch] |
+ [Prompt] |
other buffer |
~ |
~ |
@@ -59,7 +59,7 @@ describe('prompt buffer', function()
Command: "hello" |
Result: "hello" |
% ^ |
- [Scratch] |
+ [Prompt] |
other buffer |
~ |
~ |
@@ -87,7 +87,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- [Scratch] |
+ [Prompt] |
other buffer |
~ |
~ |
@@ -101,7 +101,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- [Scratch] |
+ [Prompt] |
other buffer |
~ |
~ |
@@ -114,7 +114,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- [Scratch] |
+ [Prompt] |
other buffer |
~ |
~ |
@@ -127,7 +127,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- [Scratch] |
+ [Prompt] |
other buffer |
~ |
~ |