mirror of
https://github.com/neovim/neovim.git
synced 2025-10-15 06:16:08 +00:00
vim-patch:9.1.0507: hard to detect cursor movement in the command line
Problem: hard to detect cursor movement in the command line
Solution: Add the CursorMovedC autocommand
(Shougo Matsushita)
closes: vim/vim#15040
d09521476f
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
This commit is contained in:
@@ -133,7 +133,8 @@ typedef struct {
|
||||
int did_wild_list; // did wild_list() recently
|
||||
int wim_index; // index in wim_flags[]
|
||||
int save_msg_scroll;
|
||||
int save_State; // remember State when called
|
||||
int save_State; // remember State when called
|
||||
int save_cmdspos;
|
||||
char *save_p_icm;
|
||||
int some_key_typed; // one of the keys was typed
|
||||
// mouse drag and release events are ignored, unless they are
|
||||
@@ -223,6 +224,12 @@ static int cmdpreview_ns = 0;
|
||||
static const char e_active_window_or_buffer_changed_or_deleted[]
|
||||
= N_("E199: Active window or buffer changed or deleted");
|
||||
|
||||
static void trigger_cmd_autocmd(int typechar, event_T evt)
|
||||
{
|
||||
char typestr[2] = { (char)typechar, NUL };
|
||||
apply_autocmds(evt, typestr, typestr, false, curbuf);
|
||||
}
|
||||
|
||||
static void save_viewstate(win_T *wp, viewstate_T *vs)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
@@ -684,6 +691,7 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear
|
||||
.indent = indent,
|
||||
.save_msg_scroll = msg_scroll,
|
||||
.save_State = State,
|
||||
.save_cmdspos = ccline.cmdspos,
|
||||
.ignore_drag_release = true,
|
||||
};
|
||||
CommandLineState *s = &state;
|
||||
@@ -2175,6 +2183,11 @@ static int command_line_handle_key(CommandLineState *s)
|
||||
|
||||
static int command_line_not_changed(CommandLineState *s)
|
||||
{
|
||||
// Trigger CursorMovedC autocommands.
|
||||
if (ccline.cmdspos != s->save_cmdspos) {
|
||||
trigger_cmd_autocmd(get_cmdline_type(), EVENT_CURSORMOVEDC);
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -4177,6 +4190,10 @@ static int set_cmdline_pos(int pos)
|
||||
} else {
|
||||
new_cmdpos = pos;
|
||||
}
|
||||
|
||||
// Trigger CursorMovedC autocommands.
|
||||
trigger_cmd_autocmd(get_cmdline_type(), EVENT_CURSORMOVEDC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4303,7 +4320,6 @@ static int open_cmdwin(void)
|
||||
win_T *old_curwin = curwin;
|
||||
int i;
|
||||
garray_T winsizes;
|
||||
char typestr[2];
|
||||
int save_restart_edit = restart_edit;
|
||||
int save_State = State;
|
||||
bool save_exmode = exmode_active;
|
||||
@@ -4446,9 +4462,7 @@ static int open_cmdwin(void)
|
||||
cmdwin_result = 0;
|
||||
|
||||
// Trigger CmdwinEnter autocommands.
|
||||
typestr[0] = (char)cmdwin_type;
|
||||
typestr[1] = NUL;
|
||||
apply_autocmds(EVENT_CMDWINENTER, typestr, typestr, false, curbuf);
|
||||
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER);
|
||||
if (restart_edit != 0) { // autocmd with ":startinsert"
|
||||
stuffcharReadbuff(K_NOP);
|
||||
}
|
||||
@@ -4466,7 +4480,7 @@ static int open_cmdwin(void)
|
||||
const bool save_KeyTyped = KeyTyped;
|
||||
|
||||
// Trigger CmdwinLeave autocommands.
|
||||
apply_autocmds(EVENT_CMDWINLEAVE, typestr, typestr, false, curbuf);
|
||||
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE);
|
||||
|
||||
// Restore KeyTyped in case it is modified by autocommands
|
||||
KeyTyped = save_KeyTyped;
|
||||
|
Reference in New Issue
Block a user