mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
fix(events): trigger VimResume on next UI request (#24426)
This commit is contained in:
@@ -215,6 +215,8 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona
|
||||
|
||||
pmap_put(uint64_t)(&connected_uis, channel_id, ui);
|
||||
ui_attach_impl(ui, channel_id);
|
||||
|
||||
may_trigger_vim_suspend_resume(false);
|
||||
}
|
||||
|
||||
/// @deprecated
|
||||
@@ -237,6 +239,10 @@ void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error)
|
||||
return;
|
||||
}
|
||||
|
||||
if (gained) {
|
||||
may_trigger_vim_suspend_resume(false);
|
||||
}
|
||||
|
||||
do_autocmd_focusgained((bool)gained);
|
||||
}
|
||||
|
||||
|
@@ -305,6 +305,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_ks)
|
||||
Integer nvim_input(String keys)
|
||||
FUNC_API_SINCE(1) FUNC_API_FAST
|
||||
{
|
||||
may_trigger_vim_suspend_resume(false);
|
||||
return (Integer)input_enqueue(keys);
|
||||
}
|
||||
|
||||
@@ -334,6 +335,8 @@ void nvim_input_mouse(String button, String action, String modifier, Integer gri
|
||||
Integer col, Error *err)
|
||||
FUNC_API_SINCE(6) FUNC_API_FAST
|
||||
{
|
||||
may_trigger_vim_suspend_resume(false);
|
||||
|
||||
if (button.data == NULL || action.data == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
@@ -46,6 +46,7 @@
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/types.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/ui_compositor.h"
|
||||
#include "nvim/vim.h"
|
||||
@@ -2521,6 +2522,30 @@ static bool arg_autocmd_flag_get(bool *flag, char **cmd_ptr, char *pattern, int
|
||||
return false;
|
||||
}
|
||||
|
||||
/// When kFalse: VimSuspend should be triggered next.
|
||||
/// When kTrue: VimResume should be triggerd next.
|
||||
/// When kNone: Currently triggering VimSuspend or VimResume.
|
||||
static TriState pending_vimresume = kFalse;
|
||||
|
||||
static void vimresume_event(void **argv)
|
||||
{
|
||||
apply_autocmds(EVENT_VIMRESUME, NULL, NULL, false, NULL);
|
||||
pending_vimresume = kFalse;
|
||||
}
|
||||
|
||||
/// Trigger VimSuspend or VimResume autocommand.
|
||||
void may_trigger_vim_suspend_resume(bool suspend)
|
||||
{
|
||||
if (suspend && pending_vimresume == kFalse) {
|
||||
pending_vimresume = kNone;
|
||||
apply_autocmds(EVENT_VIMSUSPEND, NULL, NULL, false, NULL);
|
||||
pending_vimresume = kTrue;
|
||||
} else if (!suspend && pending_vimresume == kTrue) {
|
||||
pending_vimresume = kNone;
|
||||
multiqueue_put(main_loop.events, vimresume_event, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// UI Enter
|
||||
void do_autocmd_uienter(uint64_t chanid, bool attached)
|
||||
{
|
||||
|
@@ -4874,12 +4874,9 @@ static void ex_stop(exarg_T *eap)
|
||||
if (!eap->forceit) {
|
||||
autowrite_all();
|
||||
}
|
||||
apply_autocmds(EVENT_VIMSUSPEND, NULL, NULL, false, NULL);
|
||||
|
||||
may_trigger_vim_suspend_resume(true);
|
||||
ui_call_suspend();
|
||||
ui_flush();
|
||||
|
||||
apply_autocmds(EVENT_VIMRESUME, NULL, NULL, false, NULL);
|
||||
}
|
||||
|
||||
/// ":exit", ":xit" and ":wq": Write file and quit the current window.
|
||||
|
Reference in New Issue
Block a user