aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/state.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-21 11:11:02 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-08-21 14:16:16 +0800
commit4956f267449ca7526145c63ef095bfd731174635 (patch)
tree5933bdab52411f2905002f2566559725807a62b9 /src/nvim/state.c
parentab45d5bf6d46abd9b29389dee6689044fd63e225 (diff)
downloadrneovim-4956f267449ca7526145c63ef095bfd731174635.tar.gz
rneovim-4956f267449ca7526145c63ef095bfd731174635.tar.bz2
rneovim-4956f267449ca7526145c63ef095bfd731174635.zip
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. https://github.com/vim/vim/commit/69198cb8c08f124729c41a4681f2d142228a9139 SafeStateAgain is N/A. Move SafeState functions to state.c. Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/state.c')
-rw-r--r--src/nvim/state.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nvim/state.c b/src/nvim/state.c
index f3c2b52024..0e12c34348 100644
--- a/src/nvim/state.c
+++ b/src/nvim/state.c
@@ -268,3 +268,30 @@ void may_trigger_modechanged(void)
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;
+}