mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 05:58:33 +00:00
vim-patch:8.1.2046: SafeState may be triggered at the wrong moment
Problem: SafeState may be triggered at the wrong moment.
Solution: Move it up higher to after where messages are processed. Add a
SafeStateAgain event to tigger there.
69198cb8c0
SafeStateAgain is N/A.
Move SafeState functions to state.c.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -619,6 +619,7 @@ Eval:
|
|||||||
*v:sizeofpointer*
|
*v:sizeofpointer*
|
||||||
|
|
||||||
Events:
|
Events:
|
||||||
|
*SafeStateAgain*
|
||||||
*SigUSR1* Use |Signal| to detect `SIGUSR1` signal instead.
|
*SigUSR1* Use |Signal| to detect `SIGUSR1` signal instead.
|
||||||
|
|
||||||
Highlight groups:
|
Highlight groups:
|
||||||
|
@@ -885,6 +885,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
|
|||||||
if (++typebuf.tb_change_cnt == 0) {
|
if (++typebuf.tb_change_cnt == 0) {
|
||||||
typebuf.tb_change_cnt = 1;
|
typebuf.tb_change_cnt = 1;
|
||||||
}
|
}
|
||||||
|
state_no_longer_safe();
|
||||||
|
|
||||||
addlen = (int)strlen(str);
|
addlen = (int)strlen(str);
|
||||||
|
|
||||||
@@ -1625,6 +1626,12 @@ int vgetc(void)
|
|||||||
// Execute Lua on_key callbacks.
|
// Execute Lua on_key callbacks.
|
||||||
nlua_execute_on_key(c);
|
nlua_execute_on_key(c);
|
||||||
|
|
||||||
|
// Need to process the character before we know it's safe to do something
|
||||||
|
// else.
|
||||||
|
if (c != K_IGNORE) {
|
||||||
|
state_no_longer_safe();
|
||||||
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -482,40 +482,6 @@ bool check_text_or_curbuf_locked(oparg_T *oap)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool was_safe = false;
|
|
||||||
static int not_safe_now = 0;
|
|
||||||
|
|
||||||
/// Trigger SafeState if currently in s safe state, that is "safe" is TRUE and
|
|
||||||
/// there is no typeahead.
|
|
||||||
void may_trigger_safestate(bool safe)
|
|
||||||
{
|
|
||||||
bool is_safe = safe
|
|
||||||
&& stuff_empty()
|
|
||||||
&& typebuf.tb_len == 0
|
|
||||||
&& !global_busy;
|
|
||||||
|
|
||||||
if (is_safe) {
|
|
||||||
apply_autocmds(EVENT_SAFESTATE, NULL, NULL, false, curbuf);
|
|
||||||
}
|
|
||||||
was_safe = is_safe;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Entering a not-safe state.
|
|
||||||
void enter_unsafe_state(void)
|
|
||||||
{
|
|
||||||
not_safe_now++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Leaving a not-safe state. Trigger SafeState if we were in a safe state
|
|
||||||
/// before first calling enter_not_safe_state().
|
|
||||||
void leave_unsafe_state(void)
|
|
||||||
{
|
|
||||||
not_safe_now--;
|
|
||||||
if (not_safe_now == 0 && was_safe) {
|
|
||||||
apply_autocmds(EVENT_SAFESTATE, NULL, NULL, false, curbuf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Normal state entry point. This is called on:
|
/// Normal state entry point. This is called on:
|
||||||
///
|
///
|
||||||
/// - Startup, In this case the function never returns.
|
/// - Startup, In this case the function never returns.
|
||||||
@@ -1434,7 +1400,7 @@ static int normal_check(VimState *state)
|
|||||||
quit_more = false;
|
quit_more = false;
|
||||||
|
|
||||||
// it's not safe unless normal_check_safe_state() is called
|
// it's not safe unless normal_check_safe_state() is called
|
||||||
was_safe = false;
|
state_no_longer_safe();
|
||||||
|
|
||||||
// If skip redraw is set (for ":" in wait_return()), don't redraw now.
|
// If skip redraw is set (for ":" in wait_return()), don't redraw now.
|
||||||
// If there is nothing in the stuff_buffer or do_redraw is true,
|
// If there is nothing in the stuff_buffer or do_redraw is true,
|
||||||
|
@@ -268,3 +268,30 @@ void may_trigger_modechanged(void)
|
|||||||
|
|
||||||
restore_v_event(v_event, &save_v_event);
|
restore_v_event(v_event, &save_v_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// When true in a safe state when starting to wait for a character.
|
||||||
|
static bool was_safe = false;
|
||||||
|
|
||||||
|
/// Trigger SafeState if currently in s safe state, that is "safe" is TRUE and
|
||||||
|
/// there is no typeahead.
|
||||||
|
void may_trigger_safestate(bool safe)
|
||||||
|
{
|
||||||
|
bool is_safe = safe
|
||||||
|
&& stuff_empty()
|
||||||
|
&& typebuf.tb_len == 0
|
||||||
|
&& !using_script()
|
||||||
|
&& !global_busy;
|
||||||
|
|
||||||
|
if (is_safe) {
|
||||||
|
apply_autocmds(EVENT_SAFESTATE, NULL, NULL, false, curbuf);
|
||||||
|
}
|
||||||
|
was_safe = is_safe;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Something changed which causes the state possibly to be unsafe, e.g. a
|
||||||
|
/// character was typed. It will remain unsafe until the next call to
|
||||||
|
/// may_trigger_safestate().
|
||||||
|
void state_no_longer_safe(void)
|
||||||
|
{
|
||||||
|
was_safe = false;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user