aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-11-21 12:48:30 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-11-21 15:39:04 -0300
commite15485c5d659977d0a8f20f7f7f319dac2423a0e (patch)
tree900108cc33642746707565f2a7483dc27f5448fd /src
parent2c29b20af767bd7ebebeb41da14df4d66a19d5a0 (diff)
downloadrneovim-e15485c5d659977d0a8f20f7f7f319dac2423a0e.tar.gz
rneovim-e15485c5d659977d0a8f20f7f7f319dac2423a0e.tar.bz2
rneovim-e15485c5d659977d0a8f20f7f7f319dac2423a0e.zip
input: Refactor to ensure user input has higher priority
Diffstat (limited to 'src')
-rw-r--r--src/nvim/os/input.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index 3ebfb3f12b..d10d20b20e 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -84,13 +84,11 @@ void input_stop(void)
// Low level input function.
int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
{
- InbufPollResult result;
-
- if (event_has_deferred()) {
- // Return pending event bytes
- return push_event_key(buf, maxlen);
+ if (rbuffer_pending(input_buffer)) {
+ return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
}
+ InbufPollResult result;
if (ms >= 0) {
if ((result = inbuf_poll(ms)) == kInputNone) {
return 0;
@@ -110,24 +108,27 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
}
}
- // If there are deferred events, return the keys directly
- if (event_has_deferred()) {
- return push_event_key(buf, maxlen);
- }
-
// If input was put directly in typeahead buffer bail out here.
if (typebuf_changed(tb_change_cnt)) {
return 0;
}
+ if (rbuffer_pending(input_buffer)) {
+ // Safe to convert rbuffer_read to int, it will never overflow since we use
+ // relatively small buffers.
+ return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
+ }
+
+ // If there are deferred events, return the keys directly
+ if (event_has_deferred()) {
+ return push_event_key(buf, maxlen);
+ }
+
if (result == kInputEof) {
read_error_exit();
- return 0;
}
- // Safe to convert rbuffer_read to int, it will never overflow since
- // we use relatively small buffers.
- return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
+ return 0;
}
// Check if a character is available for reading
@@ -319,10 +320,9 @@ static int push_event_key(uint8_t *buf, int maxlen)
// Check if there's pending input
static bool input_ready(void)
{
- return typebuf_was_filled || // API call filled typeahead
- event_has_deferred() || // Events must be processed
- (!embedded_mode && (
- rbuffer_pending(input_buffer) > 0 || // Stdin input
- eof)); // Stdin closed
+ return typebuf_was_filled || // API call filled typeahead
+ rbuffer_pending(input_buffer) > 0 || // Stdin input
+ event_has_deferred() || // Events must be processed
+ (!embedded_mode && eof); // Stdin closed
}