summaryrefslogtreecommitdiffstats
path: root/src/gui.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-12-18 18:14:47 +0100
committerBram Moolenaar <Bram@vim.org>2017-12-18 18:14:47 +0100
commitc9e649ae816cdff0d1da8a97d40e695c6d3991bd (patch)
treeb9e52b1126c83609c9b5dae5305e535bc4002a10 /src/gui.c
parent606d45ccd8a2ad2956e2729f6135fd79fd2f6d72 (diff)
patch 8.0.1405: duplicated code for getting a typed characterv8.0.1405
Problem: Duplicated code for getting a typed character. CursorHold is called too often in the GUI. (lilydjwg) Solution: Refactor code to move code up from mch_inchar(). Don't fire CursorHold if feedkeys() was used. (closes #2451)
Diffstat (limited to 'src/gui.c')
-rw-r--r--src/gui.c64
1 files changed, 33 insertions, 31 deletions
diff --git a/src/gui.c b/src/gui.c
index 5aa8214f5f..7026a11d0c 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -2886,6 +2886,18 @@ gui_insert_lines(int row, int count)
}
/*
+ * Passed to ui_wait_for_chars_or_timer(), ignoring extra arguments.
+ */
+ static int
+gui_wait_for_chars_3(
+ long wtime,
+ int *interrupted UNUSED,
+ int ignore_input UNUSED)
+{
+ return gui_mch_wait_for_chars(wtime);
+}
+
+/*
* Returns OK if a character was found to be available within the given time,
* or FAIL otherwise.
*/
@@ -2893,32 +2905,7 @@ gui_insert_lines(int row, int count)
gui_wait_for_chars_or_timer(long wtime)
{
#ifdef FEAT_TIMERS
- int due_time;
- long remaining = wtime;
- int tb_change_cnt = typebuf.tb_change_cnt;
-
- /* When waiting very briefly don't trigger timers. */
- if (wtime >= 0 && wtime < 10L)
- return gui_mch_wait_for_chars(wtime);
-
- while (wtime < 0 || remaining > 0)
- {
- /* Trigger timers and then get the time in wtime until the next one is
- * due. Wait up to that time. */
- due_time = check_due_timer();
- if (typebuf.tb_change_cnt != tb_change_cnt)
- {
- /* timer may have used feedkeys() */
- return FAIL;
- }
- if (due_time <= 0 || (wtime > 0 && due_time > remaining))
- due_time = remaining;
- if (gui_mch_wait_for_chars(due_time))
- return OK;
- if (wtime > 0)
- remaining -= due_time;
- }
- return FAIL;
+ return ui_wait_for_chars_or_timer(wtime, gui_wait_for_chars_3, NULL, 0);
#else
return gui_mch_wait_for_chars(wtime);
#endif
@@ -2933,10 +2920,9 @@ gui_wait_for_chars_or_timer(long wtime)
* or FAIL otherwise.
*/
int
-gui_wait_for_chars(long wtime)
+gui_wait_for_chars(long wtime, int tb_change_cnt)
{
int retval;
- int tb_change_cnt = typebuf.tb_change_cnt;
#ifdef FEAT_MENU
/*
@@ -2974,13 +2960,13 @@ gui_wait_for_chars(long wtime)
retval = FAIL;
/*
* We may want to trigger the CursorHold event. First wait for
- * 'updatetime' and if nothing is typed within that time put the
- * K_CURSORHOLD key in the input buffer.
+ * 'updatetime' and if nothing is typed within that time, and feedkeys()
+ * wasn't used, put the K_CURSORHOLD key in the input buffer.
*/
if (gui_wait_for_chars_or_timer(p_ut) == OK)
retval = OK;
#ifdef FEAT_AUTOCMD
- else if (trigger_cursorhold())
+ else if (trigger_cursorhold() && typebuf.tb_change_cnt == tb_change_cnt)
{
char_u buf[3];
@@ -3006,6 +2992,22 @@ gui_wait_for_chars(long wtime)
}
/*
+ * Equivalent of mch_inchar() for the GUI.
+ */
+ int
+gui_inchar(
+ char_u *buf,
+ int maxlen,
+ long wtime, /* milli seconds */
+ int tb_change_cnt)
+{
+ if (gui_wait_for_chars(wtime, tb_change_cnt)
+ && !typebuf_changed(tb_change_cnt))
+ return read_from_input_buf(buf, (long)maxlen);
+ return 0;
+}
+
+/*
* Fill p[4] with mouse coordinates encoded for check_termcode().
*/
static void