mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
event: No longer process K_EVENT automatically
Two new functions, `event_enable_deferred()`/`event_disable_deferred()` have to be called by code that is capable of handling asynchronicity. User-dialog states like "press ENTER to continue" or the swap file confirmation no longer will generate K_EVENT.
This commit is contained in:
parent
230c935e73
commit
f09a33bbc1
@ -593,9 +593,17 @@ edit (
|
||||
* Get a character for Insert mode. Ignore K_IGNORE.
|
||||
*/
|
||||
lastc = c; /* remember previous char for CTRL-D */
|
||||
event_enable_deferred();
|
||||
do {
|
||||
c = safe_vgetc();
|
||||
} while (c == K_IGNORE);
|
||||
event_disable_deferred();
|
||||
|
||||
if (c == K_EVENT) {
|
||||
c = lastc;
|
||||
event_process();
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
|
||||
did_cursorhold = TRUE;
|
||||
@ -943,10 +951,6 @@ doESCkey:
|
||||
did_cursorhold = TRUE;
|
||||
break;
|
||||
|
||||
case K_EVENT:
|
||||
event_process();
|
||||
break;
|
||||
|
||||
case K_HOME: /* <Home> */
|
||||
case K_KHOME:
|
||||
case K_S_HOME:
|
||||
|
@ -311,9 +311,16 @@ getcmdline (
|
||||
|
||||
/* Get a character. Ignore K_IGNORE, it should not do anything, such
|
||||
* as stop completion. */
|
||||
event_enable_deferred();
|
||||
do {
|
||||
c = safe_vgetc();
|
||||
} while (c == K_IGNORE);
|
||||
event_disable_deferred();
|
||||
|
||||
if (c == K_EVENT) {
|
||||
event_process();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (KeyTyped) {
|
||||
some_key_typed = TRUE;
|
||||
@ -769,11 +776,6 @@ getcmdline (
|
||||
* Big switch for a typed command line character.
|
||||
*/
|
||||
switch (c) {
|
||||
case K_EVENT:
|
||||
event_process();
|
||||
// Force a redraw even though the command line didn't change
|
||||
shell_resized();
|
||||
goto cmdline_not_changed;
|
||||
case K_BS:
|
||||
case Ctrl_H:
|
||||
case K_DEL:
|
||||
@ -1885,8 +1887,6 @@ redraw:
|
||||
}
|
||||
|
||||
if (IS_SPECIAL(c1)) {
|
||||
// Process deferred events
|
||||
event_process();
|
||||
// Ignore other special key codes
|
||||
continue;
|
||||
}
|
||||
|
@ -2481,7 +2481,6 @@ inchar (
|
||||
char_u dum[DUM_LEN + 1];
|
||||
|
||||
for (;; ) {
|
||||
event_process();
|
||||
len = ui_inchar(dum, DUM_LEN, 0L, 0);
|
||||
if (len == 0 || (len == 1 && dum[0] == 3))
|
||||
break;
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "nvim/term.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/event.h"
|
||||
|
||||
/*
|
||||
* To be able to scroll back at the "more" and "hit-enter" prompts we need to
|
||||
@ -2076,9 +2075,6 @@ static int do_more_prompt(int typed_char)
|
||||
|
||||
toscroll = 0;
|
||||
switch (c) {
|
||||
case K_EVENT:
|
||||
event_process();
|
||||
break;
|
||||
case BS: /* scroll one line back */
|
||||
case K_BS:
|
||||
case 'k':
|
||||
@ -2738,8 +2734,6 @@ do_dialog (
|
||||
break;
|
||||
default: /* Could be a hotkey? */
|
||||
if (c < 0) { /* special keys are ignored here */
|
||||
// drain event queue to prevent infinite loop
|
||||
event_process();
|
||||
continue;
|
||||
}
|
||||
if (c == ':' && ex_cmd) {
|
||||
|
@ -312,7 +312,6 @@ static const struct nv_cmd {
|
||||
{K_F8, farsi_fkey, 0, 0},
|
||||
{K_F9, farsi_fkey, 0, 0},
|
||||
{K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0},
|
||||
{K_EVENT, nv_event, NV_KEEPREG, 0},
|
||||
};
|
||||
|
||||
/* Number of commands in nv_cmds[]. */
|
||||
@ -483,7 +482,15 @@ normal_cmd (
|
||||
/*
|
||||
* Get the command character from the user.
|
||||
*/
|
||||
event_enable_deferred();
|
||||
c = safe_vgetc();
|
||||
event_disable_deferred();
|
||||
|
||||
if (c == K_EVENT) {
|
||||
event_process();
|
||||
return;
|
||||
}
|
||||
|
||||
LANGMAP_ADJUST(c, true);
|
||||
|
||||
/*
|
||||
@ -7373,8 +7380,3 @@ static void nv_cursorhold(cmdarg_T *cap)
|
||||
did_cursorhold = true;
|
||||
cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */
|
||||
}
|
||||
|
||||
static void nv_event(cmdarg_T *cap)
|
||||
{
|
||||
event_process();
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/term.h"
|
||||
#include "nvim/screen.h"
|
||||
|
||||
#include "nvim/lib/klist.h"
|
||||
|
||||
@ -39,6 +41,7 @@ typedef struct {
|
||||
// loop(to avoid recursion), but before returning from
|
||||
// `event_poll`
|
||||
static klist_t(Event) *deferred_events = NULL, *immediate_events = NULL;
|
||||
static int deferred_events_allowed = 0;
|
||||
|
||||
void event_init(void)
|
||||
{
|
||||
@ -134,7 +137,17 @@ void event_poll(int ms)
|
||||
|
||||
bool event_has_deferred(void)
|
||||
{
|
||||
return !kl_empty(deferred_events);
|
||||
return deferred_events_allowed && !kl_empty(deferred_events);
|
||||
}
|
||||
|
||||
void event_enable_deferred(void)
|
||||
{
|
||||
++deferred_events_allowed;
|
||||
}
|
||||
|
||||
void event_disable_deferred(void)
|
||||
{
|
||||
--deferred_events_allowed;
|
||||
}
|
||||
|
||||
// Queue an event
|
||||
@ -146,6 +159,11 @@ void event_push(Event event, bool deferred)
|
||||
void event_process(void)
|
||||
{
|
||||
process_events_from(deferred_events);
|
||||
|
||||
if (must_redraw) {
|
||||
update_screen(0);
|
||||
out_flush();
|
||||
}
|
||||
}
|
||||
|
||||
static void process_events_from(klist_t(Event) *queue)
|
||||
|
Loading…
Reference in New Issue
Block a user