mirror of
https://github.com/neovim/neovim.git
synced 2025-09-26 21:18:34 +00:00
state: throttle batched event processing when input is available
before, calling vim.schedule() from inside an event would execute the scheduled callback immediately after this event without checking for user input in between. Break event processing whenever user input or an interrupt is available.
This commit is contained in:
@@ -75,6 +75,34 @@ getkey:
|
||||
}
|
||||
}
|
||||
|
||||
/// process events on main_loop, but interrupt if input is available
|
||||
///
|
||||
/// This should be used to handle K_EVENT in states accepting input
|
||||
/// otherwise bursts of events can block break checking indefinitely.
|
||||
void state_handle_k_event(void)
|
||||
{
|
||||
while (true) {
|
||||
Event event = multiqueue_get(main_loop.events);
|
||||
if (event.handler) {
|
||||
event.handler(event.argv);
|
||||
}
|
||||
|
||||
if (multiqueue_empty(main_loop.events)) {
|
||||
// don't breakcheck before return, caller should return to main-loop
|
||||
// and handle input already.
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(bfredl): as an further micro-optimization, we could check whether
|
||||
// event.handler already checked input.
|
||||
os_breakcheck();
|
||||
if (input_available() || got_int) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Return true if in the current mode we need to use virtual.
|
||||
bool virtual_active(void)
|
||||
{
|
||||
|
Reference in New Issue
Block a user