aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/input.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-01-04 19:04:21 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2021-03-08 16:08:58 +0100
commitf901149de4bc69f7aa4abe00dea13bca99b9c765 (patch)
tree60857ad16af1a036af89ab7c125dc250f9423f54 /src/nvim/os/input.c
parentc12ea02e0b5d465e2c4b7d8bba028d069bdf7008 (diff)
downloadrneovim-f901149de4bc69f7aa4abe00dea13bca99b9c765.tar.gz
rneovim-f901149de4bc69f7aa4abe00dea13bca99b9c765.tar.bz2
rneovim-f901149de4bc69f7aa4abe00dea13bca99b9c765.zip
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.
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r--src/nvim/os/input.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index 9d6518841a..eca245650a 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -159,16 +159,28 @@ bool os_char_avail(void)
return inbuf_poll(0, NULL) == kInputAvail;
}
-// Check for CTRL-C typed by reading all available characters.
+/// Poll for fast events. `got_int` will be set to `true` if CTRL-C was typed.
+///
+/// This invokes a full libuv loop iteration which can be quite costly.
+/// Prefer `line_breakcheck()` if called in a busy inner loop.
+///
+/// Caller must at least check `got_int` before calling this function again.
+/// checking for other low-level input state like `input_available()` might
+/// also be relevant (i e to throttle idle processing when user input is
+/// available)
void os_breakcheck(void)
{
+ if (got_int) {
+ return;
+ }
+
int save_us = updating_screen;
// We do not want screen_resize() to redraw here.
+ // TODO(bfredl): we are already special casing redraw events, is this
+ // hack still needed?
updating_screen++;
- if (!got_int) {
- loop_poll_events(&main_loop, 0);
- }
+ loop_poll_events(&main_loop, 0);
updating_screen = save_us;
}