diff options
Diffstat (limited to 'src/nvim/ex_getln.c')
-rw-r--r-- | src/nvim/ex_getln.c | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c4169f03f0..532775ad0b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -95,19 +95,20 @@ typedef struct command_line_state { char_u *lookfor; // string to match int hiscnt; // current history line in use int histype; // history type to be used - pos_T old_cursor; - colnr_T old_curswant; - colnr_T old_leftcol; - linenr_T old_topline; - int old_topfill; - linenr_T old_botline; + pos_T old_cursor; + colnr_T old_curswant; + colnr_T old_leftcol; + linenr_T old_topline; + int old_topfill; + linenr_T old_botline; int did_incsearch; int incsearch_postponed; int did_wild_list; // did wild_list() recently int wim_index; // index in wim_flags[] int res; - int save_msg_scroll; - int save_State; // remember State when called + int save_msg_scroll; + int save_State; // remember State when called + char_u *save_p_icm; int some_key_typed; // one of the keys was typed // mouse drag and release events are ignored, unless they are // preceded with a mouse down event @@ -159,6 +160,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) s->indent = indent; s->save_msg_scroll = msg_scroll; s->save_State = State; + s->save_p_icm = vim_strsave(p_icm); s->ignore_drag_release = true; if (s->firstc == -1) { @@ -323,9 +325,12 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) need_wait_return = false; } + set_string_option_direct((char_u *)"icm", -1, s->save_p_icm, OPT_FREE, + SID_NONE); State = s->save_State; setmouse(); ui_cursor_shape(); // may show different cursor shape + xfree(s->save_p_icm); { char_u *p = ccline.cmdbuff; @@ -981,7 +986,6 @@ static int command_line_handle_key(CommandLineState *s) status_redraw_curbuf(); return command_line_not_changed(s); - // case '@': only in very old vi case Ctrl_U: // delete all characters left of the cursor s->j = ccline.cmdpos; @@ -996,7 +1000,6 @@ static int command_line_handle_key(CommandLineState *s) redrawcmd(); return command_line_changed(s); - case ESC: // get here if p_wc != ESC or when ESC typed twice case Ctrl_C: // In exmode it doesn't make sense to return. Except when @@ -1489,11 +1492,11 @@ static int command_line_handle_key(CommandLineState *s) static int command_line_not_changed(CommandLineState *s) { - // This part implements incremental searches for "/" and "?" Jump to - // cmdline_not_changed when a character has been read but the command line - // did not change. Then we only search and redraw if something changed in - // the past. Jump to cmdline_changed when the command line did change. - // (Sorry for the goto's, I know it is ugly). + // Incremental searches for "/" and "?": + // Enter command_line_not_changed() when a character has been read but the + // command line did not change. Then we only search and redraw if something + // changed in the past. + // Enter command_line_changed() when the command line did change. if (!s->incsearch_postponed) { return 1; } @@ -1592,15 +1595,21 @@ static int command_line_changed(CommandLineState *s) redrawcmdline(); s->did_incsearch = true; } else if (s->firstc == ':' - && KeyTyped // only if interactive + && current_SID == 0 // only if interactive && *p_icm != NUL // 'inccommand' is set && curbuf->b_p_ma // buffer is modifiable && cmdline_star == 0 // not typing a password - && cmd_is_live(ccline.cmdbuff)) { - // process a "live" command ('inccommand') - do_cmdline(ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_LIVE); - - // restore the window "view" + && cmd_can_preview(ccline.cmdbuff) + && !vpeekc_any()) { + // Show 'inccommand' preview. It works like this: + // 1. Do the command. + // 2. Command implementation detects CMDPREVIEW state, then: + // - Update the screen while the effects are in place. + // - Immediately undo the effects. + State |= CMDPREVIEW; + do_cmdline(ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_NOWAIT); + + // Restore the window "view". curwin->w_cursor = s->old_cursor; curwin->w_curswant = s->old_curswant; curwin->w_leftcol = s->old_leftcol; @@ -1610,6 +1619,9 @@ static int command_line_changed(CommandLineState *s) update_topline(); redrawcmdline(); + } else if (State & CMDPREVIEW) { + State = (State & ~CMDPREVIEW); + update_screen(SOME_VALID); // Clear 'inccommand' preview. } if (cmdmsg_rl || (p_arshape && !p_tbidi && enc_utf8)) { |