Skip to content

Commit 6d41c78

Browse files
committed
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.
1 parent adb8fbe commit 6d41c78

5 files changed

Lines changed: 82 additions & 1 deletion

File tree

src/edit.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,14 @@ edit(
811811
do
812812
{
813813
c = safe_vgetc();
814+
815+
if (stop_insert_mode)
816+
{
817+
// Insert mode ended, possibly from a callback.
818+
count = 0;
819+
nomove = TRUE;
820+
goto doESCkey;
821+
}
814822
} while (c == K_IGNORE || c == K_NOP);
815823

816824
/* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
@@ -1165,6 +1173,18 @@ edit(
11651173
break;
11661174

11671175
case Ctrl_W: /* delete word before the cursor */
1176+
#ifdef FEAT_JOB_CHANNEL
1177+
if (bt_prompt(curbuf) && (mod_mask & MOD_MASK_SHIFT) == 0)
1178+
{
1179+
// In a prompt window CTRL-W is used for window commands.
1180+
// Use Shift-CTRL-W to delete a word.
1181+
stuffcharReadbuff(Ctrl_W);
1182+
restart_edit = 'i';
1183+
nomove = TRUE;
1184+
count = 0;
1185+
goto doESCkey;
1186+
}
1187+
#endif
11681188
did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
11691189
auto_format(FALSE, TRUE);
11701190
break;
@@ -1869,6 +1889,19 @@ init_prompt(int cmdchar_todo)
18691889
coladvance((colnr_T)MAXCOL);
18701890
changed_bytes(curbuf->b_ml.ml_line_count, 0);
18711891
}
1892+
1893+
// Insert always starts after the prompt, allow editing text after it.
1894+
if (Insstart_orig.lnum != curwin->w_cursor.lnum
1895+
|| Insstart_orig.col != (int)STRLEN(prompt))
1896+
{
1897+
Insstart.lnum = curwin->w_cursor.lnum;
1898+
Insstart.col = STRLEN(prompt);
1899+
Insstart_orig = Insstart;
1900+
Insstart_textlen = Insstart.col;
1901+
Insstart_blank_vcol = MAXCOL;
1902+
arrow_used = FALSE;
1903+
}
1904+
18721905
if (cmdchar_todo == 'A')
18731906
coladvance((colnr_T)MAXCOL);
18741907
if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt))

src/ex_docmd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7341,7 +7341,8 @@ ex_close(exarg_T *eap)
73417341
{
73427342
if (eap->addr_count == 0)
73437343
ex_win_close(eap->forceit, curwin, NULL);
7344-
else {
7344+
else
7345+
{
73457346
FOR_ALL_WINDOWS(win)
73467347
{
73477348
winnr++;

src/structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,8 @@ struct file_buffer
23602360
char_u *b_prompt_text; // set by prompt_setprompt()
23612361
char_u *b_prompt_callback; // set by prompt_setcallback()
23622362
partial_T *b_prompt_partial; // set by prompt_setcallback()
2363+
int b_prompt_insert; // value for restart_edit when entering
2364+
// a prompt buffer window.
23632365
#endif
23642366
#ifdef FEAT_MZSCHEME
23652367
void *b_mzscheme_ref; /* The MzScheme reference to this buffer */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
35,
764766
/**/
765767
34,
766768
/**/

src/window.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,29 @@ win_equal_rec(
21032103
}
21042104
}
21052105

2106+
#ifdef FEAT_JOB_CHANNEL
2107+
static void
2108+
leaving_window(win_T *win)
2109+
{
2110+
// When leaving a prompt window stop Insert mode and perhaps restart
2111+
// it when entering that window again.
2112+
win->w_buffer->b_prompt_insert = restart_edit;
2113+
restart_edit = NUL;
2114+
2115+
// When leaving the window (or closing the window) was done from a
2116+
// callback we need to break out of the Insert mode loop.
2117+
if (State & INSERT)
2118+
stop_insert_mode = TRUE;
2119+
}
2120+
2121+
static void
2122+
entering_window(win_T *win)
2123+
{
2124+
// When entering the prompt window may restart Insert mode.
2125+
restart_edit = win->w_buffer->b_prompt_insert;
2126+
}
2127+
#endif
2128+
21062129
/*
21072130
* Close all windows for buffer "buf".
21082131
*/
@@ -2231,6 +2254,9 @@ close_last_window_tabpage(
22312254
if (h != tabline_height())
22322255
shell_new_rows();
22332256
}
2257+
#ifdef FEAT_JOB_CHANNEL
2258+
entering_window(curwin);
2259+
#endif
22342260
/* Since goto_tabpage_tp above did not trigger *Enter autocommands, do
22352261
* that now. */
22362262
apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
@@ -2296,6 +2322,9 @@ win_close(win_T *win, int free_buf)
22962322

22972323
if (win == curwin)
22982324
{
2325+
#ifdef FEAT_JOB_CHANNEL
2326+
leaving_window(curwin);
2327+
#endif
22992328
/*
23002329
* Guess which window is going to be the new current window.
23012330
* This may change because of the autocommands (sigh).
@@ -3649,6 +3678,9 @@ win_new_tabpage(int after)
36493678
* scrollbars. Have to update them anyway. */
36503679
gui_may_update_scrollbars();
36513680
#endif
3681+
#ifdef FEAT_JOB_CHANNEL
3682+
entering_window(curwin);
3683+
#endif
36523684

36533685
redraw_all_later(CLEAR);
36543686
apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf);
@@ -3822,6 +3854,9 @@ leave_tabpage(
38223854
{
38233855
tabpage_T *tp = curtab;
38243856

3857+
#ifdef FEAT_JOB_CHANNEL
3858+
leaving_window(curwin);
3859+
#endif
38253860
reset_VIsual_and_resel(); /* stop Visual mode */
38263861
if (trigger_leave_autocmds)
38273862
{
@@ -4318,6 +4353,11 @@ win_enter_ext(
43184353
if (wp == curwin && !curwin_invalid) /* nothing to do */
43194354
return;
43204355

4356+
#ifdef FEAT_JOB_CHANNEL
4357+
if (!curwin_invalid)
4358+
leaving_window(curwin);
4359+
#endif
4360+
43214361
if (!curwin_invalid && trigger_leave_autocmds)
43224362
{
43234363
/*
@@ -4389,6 +4429,9 @@ win_enter_ext(
43894429
shorten_fnames(TRUE);
43904430
}
43914431

4432+
#ifdef FEAT_JOB_CHANNEL
4433+
entering_window(curwin);
4434+
#endif
43924435
if (trigger_new_autocmds)
43934436
apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf);
43944437
if (trigger_enter_autocmds)

0 commit comments

Comments
 (0)