mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
normal: Extract most normal_cmd
logic into two functions
The new functions are `normal_prepare` and `normal_execute` which contain code executed before and after input is received in normal mode.
This commit is contained in:
parent
dae006a942
commit
82bb8c887c
@ -69,6 +69,7 @@ typedef struct normal_state {
|
|||||||
linenr_T conceal_old_cursor_line;
|
linenr_T conceal_old_cursor_line;
|
||||||
linenr_T conceal_new_cursor_line;
|
linenr_T conceal_new_cursor_line;
|
||||||
bool conceal_update_lines;
|
bool conceal_update_lines;
|
||||||
|
bool set_prevcount;
|
||||||
bool previous_got_int; // `got_int` was true
|
bool previous_got_int; // `got_int` was true
|
||||||
bool cmdwin; // command-line window normal mode
|
bool cmdwin; // command-line window normal mode
|
||||||
bool noexmode; // true if the normal mode was pushed from
|
bool noexmode; // true if the normal mode was pushed from
|
||||||
@ -76,6 +77,7 @@ typedef struct normal_state {
|
|||||||
bool toplevel; // top-level normal mode
|
bool toplevel; // top-level normal mode
|
||||||
oparg_T oa; // operator arguments
|
oparg_T oa; // operator arguments
|
||||||
cmdarg_T ca; // command arguments
|
cmdarg_T ca; // command arguments
|
||||||
|
int mapped_len;
|
||||||
} NormalState;
|
} NormalState;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -465,26 +467,11 @@ void normal_enter(bool cmdwin, bool noexmode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void normal_prepare(NormalState *s)
|
||||||
* Execute a command in Normal mode.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
normal_cmd (
|
|
||||||
oparg_T *oap,
|
|
||||||
bool toplevel /* true when called from main() */
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
cmdarg_T ca; /* command arguments */
|
cmdarg_T ca; /* command arguments */
|
||||||
int c;
|
int c;
|
||||||
bool ctrl_w = false; /* got CTRL-W command */
|
oparg_T *oap = &s->oa;
|
||||||
int old_col = curwin->w_curswant;
|
|
||||||
bool need_flushbuf; /* need to call ui_flush() */
|
|
||||||
pos_T old_pos; /* cursor position before command */
|
|
||||||
int mapped_len;
|
|
||||||
static int old_mapped_len = 0;
|
|
||||||
int idx;
|
|
||||||
bool set_prevcount = false;
|
|
||||||
|
|
||||||
memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */
|
memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */
|
||||||
ca.oap = oap;
|
ca.oap = oap;
|
||||||
|
|
||||||
@ -509,7 +496,7 @@ normal_cmd (
|
|||||||
* count. */
|
* count. */
|
||||||
if (!finish_op && !oap->regname) {
|
if (!finish_op && !oap->regname) {
|
||||||
ca.opcount = 0;
|
ca.opcount = 0;
|
||||||
set_prevcount = true;
|
s->set_prevcount = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore counts from before receiving K_CURSORHOLD. This means after
|
/* Restore counts from before receiving K_CURSORHOLD. This means after
|
||||||
@ -522,27 +509,31 @@ normal_cmd (
|
|||||||
oap->prev_count0 = 0;
|
oap->prev_count0 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapped_len = typebuf_maplen();
|
s->mapped_len = typebuf_maplen();
|
||||||
|
|
||||||
State = NORMAL_BUSY;
|
State = NORMAL_BUSY;
|
||||||
|
|
||||||
/* Set v:count here, when called from main() and not a stuffed
|
/* Set v:count here, when called from main() and not a stuffed
|
||||||
* command, so that v:count can be used in an expression mapping
|
* command, so that v:count can be used in an expression mapping
|
||||||
* when there is no count. Do set it for redo. */
|
* when there is no count. Do set it for redo. */
|
||||||
if (toplevel && readbuf1_empty())
|
if (s->toplevel && readbuf1_empty())
|
||||||
set_vcount_ca(&ca, &set_prevcount);
|
set_vcount_ca(&ca, &s->set_prevcount);
|
||||||
|
s->ca = ca;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
static int normal_execute(NormalState *s, int c)
|
||||||
* Get the command character from the user.
|
{
|
||||||
*/
|
cmdarg_T ca = s->ca;
|
||||||
input_enable_events();
|
bool ctrl_w = false; /* got CTRL-W command */
|
||||||
c = safe_vgetc();
|
int old_col = curwin->w_curswant;
|
||||||
input_disable_events();
|
bool need_flushbuf; /* need to call ui_flush() */
|
||||||
|
pos_T old_pos; /* cursor position before command */
|
||||||
if (c == K_EVENT) {
|
int mapped_len = s->mapped_len;
|
||||||
queue_process_events(loop.events);
|
static int old_mapped_len = 0;
|
||||||
return;
|
int idx;
|
||||||
}
|
bool set_prevcount = s->set_prevcount;
|
||||||
|
bool toplevel = s->toplevel;
|
||||||
|
oparg_T *oap = &s->oa;
|
||||||
|
|
||||||
LANGMAP_ADJUST(c, true);
|
LANGMAP_ADJUST(c, true);
|
||||||
|
|
||||||
@ -1109,6 +1100,7 @@ normal_end:
|
|||||||
|
|
||||||
/* Save count before an operator for next time. */
|
/* Save count before an operator for next time. */
|
||||||
opcount = ca.opcount;
|
opcount = ca.opcount;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function executed before each iteration of normal mode.
|
// Function executed before each iteration of normal mode.
|
||||||
@ -7627,3 +7619,25 @@ static int mouse_model_popup(void)
|
|||||||
return p_mousem[0] == 'p';
|
return p_mousem[0] == 'p';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void normal_cmd(oparg_T *oap, bool toplevel)
|
||||||
|
{
|
||||||
|
NormalState s;
|
||||||
|
normal_state_init(&s);
|
||||||
|
s.toplevel = toplevel;
|
||||||
|
s.oa = *oap;
|
||||||
|
normal_prepare(&s);
|
||||||
|
|
||||||
|
input_enable_events();
|
||||||
|
int c = safe_vgetc();
|
||||||
|
input_disable_events();
|
||||||
|
|
||||||
|
if (c == K_EVENT) {
|
||||||
|
queue_process_events(loop.events);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)normal_execute(&s, c);
|
||||||
|
|
||||||
|
end:
|
||||||
|
*oap = s.oa;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user