comparison src/gui.c @ 13060:1bdc12630fc0 v8.0.1405

patch 8.0.1405: duplicated code for getting a typed character commit https://github.com/vim/vim/commit/c9e649ae816cdff0d1da8a97d40e695c6d3991bd Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 18 18:14:47 2017 +0100 patch 8.0.1405: duplicated code for getting a typed character 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)
author Christian Brabandt <cb@256bit.org>
date Mon, 18 Dec 2017 18:15:05 +0100
parents 16b241634614
children dc160dbdcfe2
comparison
equal deleted inserted replaced
13059:5c8106a75f25 13060:1bdc12630fc0
2884 } 2884 }
2885 } 2885 }
2886 } 2886 }
2887 2887
2888 /* 2888 /*
2889 * Passed to ui_wait_for_chars_or_timer(), ignoring extra arguments.
2890 */
2891 static int
2892 gui_wait_for_chars_3(
2893 long wtime,
2894 int *interrupted UNUSED,
2895 int ignore_input UNUSED)
2896 {
2897 return gui_mch_wait_for_chars(wtime);
2898 }
2899
2900 /*
2889 * Returns OK if a character was found to be available within the given time, 2901 * Returns OK if a character was found to be available within the given time,
2890 * or FAIL otherwise. 2902 * or FAIL otherwise.
2891 */ 2903 */
2892 static int 2904 static int
2893 gui_wait_for_chars_or_timer(long wtime) 2905 gui_wait_for_chars_or_timer(long wtime)
2894 { 2906 {
2895 #ifdef FEAT_TIMERS 2907 #ifdef FEAT_TIMERS
2896 int due_time; 2908 return ui_wait_for_chars_or_timer(wtime, gui_wait_for_chars_3, NULL, 0);
2897 long remaining = wtime;
2898 int tb_change_cnt = typebuf.tb_change_cnt;
2899
2900 /* When waiting very briefly don't trigger timers. */
2901 if (wtime >= 0 && wtime < 10L)
2902 return gui_mch_wait_for_chars(wtime);
2903
2904 while (wtime < 0 || remaining > 0)
2905 {
2906 /* Trigger timers and then get the time in wtime until the next one is
2907 * due. Wait up to that time. */
2908 due_time = check_due_timer();
2909 if (typebuf.tb_change_cnt != tb_change_cnt)
2910 {
2911 /* timer may have used feedkeys() */
2912 return FAIL;
2913 }
2914 if (due_time <= 0 || (wtime > 0 && due_time > remaining))
2915 due_time = remaining;
2916 if (gui_mch_wait_for_chars(due_time))
2917 return OK;
2918 if (wtime > 0)
2919 remaining -= due_time;
2920 }
2921 return FAIL;
2922 #else 2909 #else
2923 return gui_mch_wait_for_chars(wtime); 2910 return gui_mch_wait_for_chars(wtime);
2924 #endif 2911 #endif
2925 } 2912 }
2926 2913
2931 * wtime > 0 Wait wtime milliseconds for a character. 2918 * wtime > 0 Wait wtime milliseconds for a character.
2932 * Returns OK if a character was found to be available within the given time, 2919 * Returns OK if a character was found to be available within the given time,
2933 * or FAIL otherwise. 2920 * or FAIL otherwise.
2934 */ 2921 */
2935 int 2922 int
2936 gui_wait_for_chars(long wtime) 2923 gui_wait_for_chars(long wtime, int tb_change_cnt)
2937 { 2924 {
2938 int retval; 2925 int retval;
2939 int tb_change_cnt = typebuf.tb_change_cnt;
2940 2926
2941 #ifdef FEAT_MENU 2927 #ifdef FEAT_MENU
2942 /* 2928 /*
2943 * If we're going to wait a bit, update the menus and mouse shape for the 2929 * If we're going to wait a bit, update the menus and mouse shape for the
2944 * current State. 2930 * current State.
2972 gui_mch_start_blink(); 2958 gui_mch_start_blink();
2973 2959
2974 retval = FAIL; 2960 retval = FAIL;
2975 /* 2961 /*
2976 * We may want to trigger the CursorHold event. First wait for 2962 * We may want to trigger the CursorHold event. First wait for
2977 * 'updatetime' and if nothing is typed within that time put the 2963 * 'updatetime' and if nothing is typed within that time, and feedkeys()
2978 * K_CURSORHOLD key in the input buffer. 2964 * wasn't used, put the K_CURSORHOLD key in the input buffer.
2979 */ 2965 */
2980 if (gui_wait_for_chars_or_timer(p_ut) == OK) 2966 if (gui_wait_for_chars_or_timer(p_ut) == OK)
2981 retval = OK; 2967 retval = OK;
2982 #ifdef FEAT_AUTOCMD 2968 #ifdef FEAT_AUTOCMD
2983 else if (trigger_cursorhold()) 2969 else if (trigger_cursorhold() && typebuf.tb_change_cnt == tb_change_cnt)
2984 { 2970 {
2985 char_u buf[3]; 2971 char_u buf[3];
2986 2972
2987 /* Put K_CURSORHOLD in the input buffer. */ 2973 /* Put K_CURSORHOLD in the input buffer. */
2988 buf[0] = CSI; 2974 buf[0] = CSI;
3001 retval = gui_wait_for_chars_or_timer(-1L); 2987 retval = gui_wait_for_chars_or_timer(-1L);
3002 } 2988 }
3003 2989
3004 gui_mch_stop_blink(); 2990 gui_mch_stop_blink();
3005 return retval; 2991 return retval;
2992 }
2993
2994 /*
2995 * Equivalent of mch_inchar() for the GUI.
2996 */
2997 int
2998 gui_inchar(
2999 char_u *buf,
3000 int maxlen,
3001 long wtime, /* milli seconds */
3002 int tb_change_cnt)
3003 {
3004 if (gui_wait_for_chars(wtime, tb_change_cnt)
3005 && !typebuf_changed(tb_change_cnt))
3006 return read_from_input_buf(buf, (long)maxlen);
3007 return 0;
3006 } 3008 }
3007 3009
3008 /* 3010 /*
3009 * Fill p[4] with mouse coordinates encoded for check_termcode(). 3011 * Fill p[4] with mouse coordinates encoded for check_termcode().
3010 */ 3012 */