comparison src/misc2.c @ 20603:c2570baa2e4c v8.2.0855

patch 8.2.0855: GUI tests fail because the test doesn't use a modifier Commit: https://github.com/vim/vim/commit/ebe9d34aa07037cff2188a8dd424ee1f59cbb0bf Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 30 21:52:54 2020 +0200 patch 8.2.0855: GUI tests fail because the test doesn't use a modifier Problem: GUI tests fail because the test doesn't use a modifier. Solution: Add "\{xxx}" to be able to encode a modifier.
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 May 2020 22:00:04 +0200
parents 4c317d8c1051
children 8bce783af0cb
comparison
equal deleted inserted replaced
20602:67dccb63d65c 20603:c2570baa2e4c
2701 */ 2701 */
2702 int 2702 int
2703 trans_special( 2703 trans_special(
2704 char_u **srcp, 2704 char_u **srcp,
2705 char_u *dst, 2705 char_u *dst,
2706 int keycode, // prefer key code, e.g. K_DEL instead of DEL 2706 int flags, // FSK_ values
2707 int in_string, // TRUE when inside a double quoted string 2707 int *did_simplify) // FSK_SIMPLIFY and found <C-H> or <A-x>
2708 int simplify, // simplify <C-H> and <A-x>
2709 int *did_simplify) // found <C-H> or <A-x>
2710 { 2708 {
2711 int modifiers = 0; 2709 int modifiers = 0;
2712 int key; 2710 int key;
2713 2711
2714 key = find_special_key(srcp, &modifiers, keycode, FALSE, in_string, 2712 key = find_special_key(srcp, &modifiers, flags, did_simplify);
2715 simplify, did_simplify);
2716 if (key == 0) 2713 if (key == 0)
2717 return 0; 2714 return 0;
2718 2715
2719 return special_to_buf(key, modifiers, keycode, dst); 2716 return special_to_buf(key, modifiers, flags & FSK_KEYCODE, dst);
2720 } 2717 }
2721 2718
2722 /* 2719 /*
2723 * Put the character sequence for "key" with "modifiers" into "dst" and return 2720 * Put the character sequence for "key" with "modifiers" into "dst" and return
2724 * the resulting length. 2721 * the resulting length.
2762 */ 2759 */
2763 int 2760 int
2764 find_special_key( 2761 find_special_key(
2765 char_u **srcp, 2762 char_u **srcp,
2766 int *modp, 2763 int *modp,
2767 int keycode, // prefer key code, e.g. K_DEL instead of DEL 2764 int flags, // FSK_ values
2768 int keep_x_key, // don't translate xHome to Home key
2769 int in_string, // TRUE in string, double quote is escaped
2770 int simplify, // simplify <C-H> and <A-x>
2771 int *did_simplify) // found <C-H> or <A-x> 2765 int *did_simplify) // found <C-H> or <A-x>
2772 { 2766 {
2773 char_u *last_dash; 2767 char_u *last_dash;
2774 char_u *end_of_name; 2768 char_u *end_of_name;
2775 char_u *src; 2769 char_u *src;
2776 char_u *bp; 2770 char_u *bp;
2771 int in_string = flags & FSK_IN_STRING;
2777 int modifiers; 2772 int modifiers;
2778 int bit; 2773 int bit;
2779 int key; 2774 int key;
2775 int endchar = (flags & FSK_CURLY) ? '}' : '>';
2780 uvarnumber_T n; 2776 uvarnumber_T n;
2781 int l; 2777 int l;
2782 2778
2783 src = *srcp; 2779 src = *srcp;
2784 if (src[0] != '<') 2780 if (src[0] != ((flags & FSK_CURLY) ? '{' : '<'))
2785 return 0; 2781 return 0;
2786 2782
2787 // Find end of modifier list 2783 // Find end of modifier list
2788 last_dash = src; 2784 last_dash = src;
2789 for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) 2785 for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++)
2798 else 2794 else
2799 l = 1; 2795 l = 1;
2800 // Anything accepted, like <C-?>. 2796 // Anything accepted, like <C-?>.
2801 // <C-"> or <M-"> are not special in strings as " is 2797 // <C-"> or <M-"> are not special in strings as " is
2802 // the string delimiter. With a backslash it works: <M-\"> 2798 // the string delimiter. With a backslash it works: <M-\">
2803 if (!(in_string && bp[1] == '"') && bp[l + 1] == '>') 2799 if (!(in_string && bp[1] == '"') && bp[l + 1] == endchar)
2804 bp += l; 2800 bp += l;
2805 else if (in_string && bp[1] == '\\' && bp[2] == '"' 2801 else if (in_string && bp[1] == '\\' && bp[2] == '"'
2806 && bp[3] == '>') 2802 && bp[3] == endchar)
2807 bp += 2; 2803 bp += 2;
2808 } 2804 }
2809 } 2805 }
2810 if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) 2806 if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3])
2811 bp += 3; // skip t_xx, xx may be '-' or '>' 2807 bp += 3; // skip t_xx, xx may be '-' or '>'/'}'
2812 else if (STRNICMP(bp, "char-", 5) == 0) 2808 else if (STRNICMP(bp, "char-", 5) == 0)
2813 { 2809 {
2814 vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE); 2810 vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE);
2815 if (l == 0) 2811 if (l == 0)
2816 { 2812 {
2820 bp += l + 5; 2816 bp += l + 5;
2821 break; 2817 break;
2822 } 2818 }
2823 } 2819 }
2824 2820
2825 if (*bp == '>') // found matching '>' 2821 if (*bp == endchar) // found matching '>' or '}'
2826 { 2822 {
2827 end_of_name = bp + 1; 2823 end_of_name = bp + 1;
2828 2824
2829 // Which modifiers are given? 2825 // Which modifiers are given?
2830 modifiers = 0x0; 2826 modifiers = 0x0;
2866 off = 2; 2862 off = 2;
2867 if (has_mbyte) 2863 if (has_mbyte)
2868 l = mb_ptr2len(last_dash + off); 2864 l = mb_ptr2len(last_dash + off);
2869 else 2865 else
2870 l = 1; 2866 l = 1;
2871 if (modifiers != 0 && last_dash[l + off] == '>') 2867 if (modifiers != 0 && last_dash[l + off] == endchar)
2872 key = PTR2CHAR(last_dash + off); 2868 key = PTR2CHAR(last_dash + off);
2873 else 2869 else
2874 { 2870 {
2875 key = get_special_key_code(last_dash + off); 2871 key = get_special_key_code(last_dash + off);
2876 if (!keep_x_key) 2872 if (!(flags & FSK_KEEP_X_KEY))
2877 key = handle_x_keys(key); 2873 key = handle_x_keys(key);
2878 } 2874 }
2879 } 2875 }
2880 2876
2881 /* 2877 /*
2888 * Only use a modifier when there is no special key code that 2884 * Only use a modifier when there is no special key code that
2889 * includes the modifier. 2885 * includes the modifier.
2890 */ 2886 */
2891 key = simplify_key(key, &modifiers); 2887 key = simplify_key(key, &modifiers);
2892 2888
2893 if (!keycode) 2889 if (!(flags & FSK_KEYCODE))
2894 { 2890 {
2895 // don't want keycode, use single byte code 2891 // don't want keycode, use single byte code
2896 if (key == K_BS) 2892 if (key == K_BS)
2897 key = BS; 2893 key = BS;
2898 else if (key == K_DEL || key == K_KDEL) 2894 else if (key == K_DEL || key == K_KDEL)
2900 } 2896 }
2901 2897
2902 // Normal Key with modifier: Try to make a single byte code. 2898 // Normal Key with modifier: Try to make a single byte code.
2903 if (!IS_SPECIAL(key)) 2899 if (!IS_SPECIAL(key))
2904 key = extract_modifiers(key, &modifiers, 2900 key = extract_modifiers(key, &modifiers,
2905 simplify, did_simplify); 2901 flags & FSK_SIMPLIFY, did_simplify);
2906 2902
2907 *modp = modifiers; 2903 *modp = modifiers;
2908 *srcp = end_of_name; 2904 *srcp = end_of_name;
2909 return key; 2905 return key;
2910 } 2906 }