diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-10-03 13:57:01 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-12-07 11:34:24 +0000 |
commit | 28134f4e78819c2bbf0344326b9d44f21eb0d736 (patch) | |
tree | f83a2f888368a0302203e04ae09bdbf51c779e6c /src/nvim/window.c | |
parent | afaad8b54ebd2ad4ba2145f4069f5017cace3c8f (diff) | |
download | rneovim-28134f4e78819c2bbf0344326b9d44f21eb0d736.tar.gz rneovim-28134f4e78819c2bbf0344326b9d44f21eb0d736.tar.bz2 rneovim-28134f4e78819c2bbf0344326b9d44f21eb0d736.zip |
vim-patch:8.1.0035: not easy to switch between prompt buffer and other windows
Problem: Not easy to switch between prompt buffer and other windows.
Solution: Accept CTRL-W commands in Insert mode. Start and stop Insert mode
as one would expect.
https://github.com/vim/vim/commit/6d41c78e353b630bc1a72cbff9160311d2a81e8c
Cherry-pick channel.txt change from:
https://github.com/vim/vim/commit/d2f3a8b8787333abf2300d38836b196955f10c00
b_prompt_insert was already ported.
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r-- | src/nvim/window.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index 3e6e42dec2..1da6c3704f 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2229,6 +2229,28 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int } } +static void leaving_window(win_T *const win) + FUNC_ATTR_NONNULL_ALL +{ + // When leaving a prompt window stop Insert mode and perhaps restart + // it when entering that window again. + win->w_buffer->b_prompt_insert = restart_edit; + restart_edit = NUL; + + // When leaving the window (or closing the window) was done from a + // callback we need to break out of the Insert mode loop. + if (State & INSERT) { + stop_insert_mode = true; + } +} + +static void entering_window(win_T *const win) + FUNC_ATTR_NONNULL_ALL +{ + // When entering the prompt window may restart Insert mode. + restart_edit = win->w_buffer->b_prompt_insert; +} + /// Closes all windows for buffer `buf`. /// /// @param keep_curwin don't close `curwin` @@ -2367,6 +2389,7 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, tabpage_T *prev shell_new_rows(); } } + entering_window(curwin); // Since goto_tabpage_tp above did not trigger *Enter autocommands, do // that now. @@ -2434,10 +2457,10 @@ int win_close(win_T *win, bool free_buf) } if (win == curwin) { - /* - * Guess which window is going to be the new current window. - * This may change because of the autocommands (sigh). - */ + leaving_window(curwin); + + // Guess which window is going to be the new current window. + // This may change because of the autocommands (sigh). if (!win->w_floating) { wp = frame2win(win_altframe(win, NULL)); } else { @@ -3801,6 +3824,8 @@ int win_new_tabpage(int after, char_u *filename) lastused_tabpage = old_curtab; + entering_window(curwin); + apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf); apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf); apply_autocmds(EVENT_TABNEW, filename, filename, false, curbuf); @@ -3956,6 +3981,7 @@ static int leave_tabpage(buf_T *new_curbuf, bool trigger_leave_autocmds) { tabpage_T *tp = curtab; + leaving_window(curwin); reset_VIsual_and_resel(); // stop Visual mode if (trigger_leave_autocmds) { if (new_curbuf != curbuf) { @@ -4478,6 +4504,10 @@ static void win_enter_ext(win_T *const wp, const int flags) return; } + if (!curwin_invalid) { + leaving_window(curwin); + } + if (!curwin_invalid && (flags & WEE_TRIGGER_LEAVE_AUTOCMDS)) { // Be careful: If autocommands delete the window, return now. if (wp->w_buffer != curbuf) { @@ -4525,6 +4555,7 @@ static void win_enter_ext(win_T *const wp, const int flags) fix_current_dir(); + entering_window(curwin); // Careful: autocommands may close the window and make "wp" invalid if (flags & WEE_TRIGGER_NEW_AUTOCMDS) { apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf); |