diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-21 11:22:25 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-08-21 14:16:16 +0800 |
commit | 64ccfdaafef56b451e3a5eed94367fad93978ec8 (patch) | |
tree | 47a238c11a2a234da43fb07cb5db6581b6a4ebcb /src/nvim/normal.c | |
parent | 4956f267449ca7526145c63ef095bfd731174635 (diff) | |
download | rneovim-64ccfdaafef56b451e3a5eed94367fad93978ec8.tar.gz rneovim-64ccfdaafef56b451e3a5eed94367fad93978ec8.tar.bz2 rneovim-64ccfdaafef56b451e3a5eed94367fad93978ec8.zip |
vim-patch:8.1.2047: cannot check the current state
Problem: Cannot check the current state.
Solution: Add the state() function.
https://github.com/vim/vim/commit/0e57dd859ecb1e8a3b91509d2f4343e839340eb8
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r-- | src/nvim/normal.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 324bfc0c46..56bc75d658 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -482,6 +482,20 @@ bool check_text_or_curbuf_locked(oparg_T *oap) return true; } +static oparg_T *current_oap = NULL; + +/// Check if an operator was started but not finished yet. +/// Includes typing a count or a register name. +bool op_pending(void) +{ + return !(current_oap != NULL + && !finish_op + && current_oap->prev_opcount == 0 + && current_oap->prev_count0 == 0 + && current_oap->op_type == OP_NOP + && current_oap->regname == NUL); +} + /// Normal state entry point. This is called on: /// /// - Startup, In this case the function never returns. @@ -490,15 +504,18 @@ bool check_text_or_curbuf_locked(oparg_T *oap) /// for example. Returns when re-entering ex mode(because ex mode recursion is /// not allowed) /// -/// This used to be called main_loop on main.c +/// This used to be called main_loop() on main.c void normal_enter(bool cmdwin, bool noexmode) { NormalState state; normal_state_init(&state); + oparg_T *prev_oap = current_oap; + current_oap = &state.oa; state.cmdwin = cmdwin; state.noexmode = noexmode; state.toplevel = (!cmdwin || cmdwin_result == 0) && !noexmode; state_enter(&state.state); + current_oap = prev_oap; } static void normal_prepare(NormalState *s) @@ -1299,12 +1316,7 @@ static void normal_check_buffer_modified(NormalState *s) /// type a character, trigger SafeState. static void normal_check_safe_state(NormalState *s) { - may_trigger_safestate(!finish_op - && s->oa.prev_opcount > 0 - && s->oa.prev_count0 == 0 - && s->oa.op_type == OP_NOP - && s->oa.regname == NUL - && restart_edit == 0); + may_trigger_safestate(!op_pending() && restart_edit == 0); } static void normal_check_folds(NormalState *s) |