aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/state.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-21 12:16:33 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-08-21 14:16:16 +0800
commit7ce2acd59be89e5e6d2ac778ad074a9ae42951cd (patch)
tree3e1c882297afabac76ed2de1a22b68e174d52556 /src/nvim/state.c
parenta0b912c6ecd4bbbcf3ebdf7c1d4e60acaa7019cb (diff)
downloadrneovim-7ce2acd59be89e5e6d2ac778ad074a9ae42951cd.tar.gz
rneovim-7ce2acd59be89e5e6d2ac778ad074a9ae42951cd.tar.bz2
rneovim-7ce2acd59be89e5e6d2ac778ad074a9ae42951cd.zip
vim-patch:8.1.2053: SafeStateAgain not triggered if callback uses feedkeys()
Problem: SafeStateAgain not triggered if callback uses feedkeys(). Solution: Check for safe state in the input loop. Make log messages easier to find. Add 'S' flag to state(). https://github.com/vim/vim/commit/d103ee78432f9036d243b18dd5aac1263d3b7dc9 Include misc1.c change from patch 8.1.2062. Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/state.c')
-rw-r--r--src/nvim/state.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/nvim/state.c b/src/nvim/state.c
index 89e4b9cbbf..ccf2a81adb 100644
--- a/src/nvim/state.c
+++ b/src/nvim/state.c
@@ -272,20 +272,26 @@ void may_trigger_modechanged(void)
/// When true in a safe state when starting to wait for a character.
static bool was_safe = false;
+/// Return whether currently it is safe, assuming it was safe before (high level
+/// state didn't change).
+static bool is_safe_now(void)
+{
+ return stuff_empty()
+ && typebuf.tb_len == 0
+ && !using_script()
+ && !global_busy;
+}
+
/// 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;
+ bool is_safe = safe && is_safe_now();
if (was_safe != is_safe) {
// Only log when the state changes, otherwise it happens at nearly
// every key stroke.
- DLOG(is_safe ? "Start triggering SafeState" : "Stop triggering SafeState");
+ DLOG(is_safe ? "SafeState: Start triggering" : "SafeState: Stop triggering");
}
if (is_safe) {
apply_autocmds(EVENT_SAFESTATE, NULL, NULL, false, curbuf);
@@ -296,10 +302,15 @@ void may_trigger_safestate(bool 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)
+void state_no_longer_safe(const char *reason)
{
- if (was_safe) {
- DLOG("safe state reset");
+ if (was_safe && reason != NULL) {
+ DLOG("SafeState reset: %s", reason);
}
was_safe = false;
}
+
+bool get_was_safe_state(void)
+{
+ return was_safe;
+}