# HG changeset patch # User Bram Moolenaar # Date 1574458203 -3600 # Node ID fb07fe556e67865e569efb85022764c72b2b6ee0 # Parent 13f864614ad3ea7bee2b81dc4a18e087c2918548 patch 8.1.2337: double-click time sometimes miscomputed Commit: https://github.com/vim/vim/commit/85c3502ef5a4c4b0f5944a89edb731f2289a706c Author: Bram Moolenaar Date: Fri Nov 22 22:21:59 2019 +0100 patch 8.1.2337: double-click time sometimes miscomputed Problem: Double-click time sometimes miscomputed. Solution: Correct time computation. (Dominique Pelle, closes https://github.com/vim/vim/issues/5259) diff --git a/src/mouse.c b/src/mouse.c --- 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 --- 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 --- a/src/version.c +++ b/src/version.c @@ -738,6 +738,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2337, +/**/ 2336, /**/ 2335,