From 85c3502ef5a4c4b0f5944a89edb731f2289a706c Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 22 Nov 2019 22:21:59 +0100 Subject: [PATCH] patch 8.1.2337: double-click time sometimes miscomputed Problem: Double-click time sometimes miscomputed. Solution: Correct time computation. (Dominique Pelle, closes #5259) --- src/mouse.c | 25 +++++++++++++++++-------- src/testdir/runtest.vim | 2 -- src/version.c | 2 ++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index c14180068..9d0e39409 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -13,6 +13,22 @@ #include "vim.h" +#ifdef CHECK_DOUBLE_CLICK +/* + * Return the duration from t1 to t2 in milliseconds. + */ + static long +time_diff_ms(struct timeval *t1, struct timeval *t2) +{ + // This handles wrapping of tv_usec correctly without any special case. + // Example of 2 pairs (tv_sec, tv_usec) with a duration of 5 ms: + // t1 = (1, 998000) t2 = (2, 3000) gives: + // (2 - 1) * 1000 + (3000 - 998000) / 1000 -> 5 ms. + return (t2->tv_sec - t1->tv_sec) * 1000 + + (t2->tv_usec - t1->tv_usec) / 1000; +} +#endif + /* * Get class of a character for selection: same class means same word. * 0: blank @@ -2713,14 +2729,7 @@ check_termcode_mouse( timediff = p_mouset; } else - { - timediff = (mouse_time.tv_usec - - orig_mouse_time.tv_usec) / 1000; - if (timediff < 0) - --orig_mouse_time.tv_sec; - timediff += (mouse_time.tv_sec - - orig_mouse_time.tv_sec) * 1000; - } + timediff = time_diff_ms(&orig_mouse_time, &mouse_time); orig_mouse_time = mouse_time; if (mouse_code == orig_mouse_code && timediff < p_mouset diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim index 2b416b910..c05bd25fe 100644 --- a/src/testdir/runtest.vim +++ b/src/testdir/runtest.vim @@ -343,8 +343,6 @@ let s:flaky_tests = [ \ 'Test_reltime()', \ 'Test_server_crash()', \ 'Test_state()', - \ 'Test_term_mouse_double_click_to_create_tab()', - \ 'Test_term_mouse_multiple_clicks_to_visually_select()', \ 'Test_terminal_ansicolors_default()', \ 'Test_terminal_ansicolors_func()', \ 'Test_terminal_ansicolors_global()', diff --git a/src/version.c b/src/version.c index 137db0ec2..996c3c576 100644 --- a/src/version.c +++ b/src/version.c @@ -737,6 +737,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2337, /**/ 2336, /**/ -- 2.40.0