Mercurial > vim
comparison src/misc2.c @ 18301:506bf60a30a0 v8.1.2145
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Commit: https://github.com/vim/vim/commit/459fd785e4a8d044147a3f83a5fca8748528aa84
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 13 16:43:39 2019 +0200
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Problem: Cannot map <C-H> when modifyOtherKeys is enabled.
Solution: Add the <C-H> mapping twice, both with modifier and as 0x08. Use
only the first one when modifyOtherKeys has been detected.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 13 Oct 2019 16:45:04 +0200 |
parents | 11f68eb58fda |
children | 6a7ebc2ee528 |
comparison
equal
deleted
inserted
replaced
18300:e502ed410b63 | 18301:506bf60a30a0 |
---|---|
2694 int | 2694 int |
2695 trans_special( | 2695 trans_special( |
2696 char_u **srcp, | 2696 char_u **srcp, |
2697 char_u *dst, | 2697 char_u *dst, |
2698 int keycode, // prefer key code, e.g. K_DEL instead of DEL | 2698 int keycode, // prefer key code, e.g. K_DEL instead of DEL |
2699 int in_string) // TRUE when inside a double quoted string | 2699 int in_string, // TRUE when inside a double quoted string |
2700 int simplify, // simplify <C-H> and <A-x> | |
2701 int *did_simplify) // found <C-H> or <A-x> | |
2700 { | 2702 { |
2701 int modifiers = 0; | 2703 int modifiers = 0; |
2702 int key; | 2704 int key; |
2703 | 2705 |
2704 key = find_special_key(srcp, &modifiers, keycode, FALSE, in_string); | 2706 key = find_special_key(srcp, &modifiers, keycode, FALSE, in_string, |
2707 simplify, did_simplify); | |
2705 if (key == 0) | 2708 if (key == 0) |
2706 return 0; | 2709 return 0; |
2707 | 2710 |
2708 return special_to_buf(key, modifiers, keycode, dst); | 2711 return special_to_buf(key, modifiers, keycode, dst); |
2709 } | 2712 } |
2751 */ | 2754 */ |
2752 int | 2755 int |
2753 find_special_key( | 2756 find_special_key( |
2754 char_u **srcp, | 2757 char_u **srcp, |
2755 int *modp, | 2758 int *modp, |
2756 int keycode, /* prefer key code, e.g. K_DEL instead of DEL */ | 2759 int keycode, // prefer key code, e.g. K_DEL instead of DEL |
2757 int keep_x_key, /* don't translate xHome to Home key */ | 2760 int keep_x_key, // don't translate xHome to Home key |
2758 int in_string) /* TRUE in string, double quote is escaped */ | 2761 int in_string, // TRUE in string, double quote is escaped |
2762 int simplify, // simplify <C-H> and <A-x> | |
2763 int *did_simplify) // found <C-H> or <A-x> | |
2759 { | 2764 { |
2760 char_u *last_dash; | 2765 char_u *last_dash; |
2761 char_u *end_of_name; | 2766 char_u *end_of_name; |
2762 char_u *src; | 2767 char_u *src; |
2763 char_u *bp; | 2768 char_u *bp; |
2833 { | 2838 { |
2834 if (STRNICMP(last_dash + 1, "char-", 5) == 0 | 2839 if (STRNICMP(last_dash + 1, "char-", 5) == 0 |
2835 && VIM_ISDIGIT(last_dash[6])) | 2840 && VIM_ISDIGIT(last_dash[6])) |
2836 { | 2841 { |
2837 /* <Char-123> or <Char-033> or <Char-0x33> */ | 2842 /* <Char-123> or <Char-033> or <Char-0x33> */ |
2838 vim_str2nr(last_dash + 6, NULL, &l, STR2NR_ALL, NULL, &n, 0, TRUE); | 2843 vim_str2nr(last_dash + 6, NULL, &l, STR2NR_ALL, NULL, |
2844 &n, 0, TRUE); | |
2839 if (l == 0) | 2845 if (l == 0) |
2840 { | 2846 { |
2841 emsg(_(e_invarg)); | 2847 emsg(_(e_invarg)); |
2842 return 0; | 2848 return 0; |
2843 } | 2849 } |
2883 key = BS; | 2889 key = BS; |
2884 else if (key == K_DEL || key == K_KDEL) | 2890 else if (key == K_DEL || key == K_KDEL) |
2885 key = DEL; | 2891 key = DEL; |
2886 } | 2892 } |
2887 | 2893 |
2888 /* | 2894 // Normal Key with modifier: Try to make a single byte code. |
2889 * Normal Key with modifier: Try to make a single byte code. | |
2890 */ | |
2891 if (!IS_SPECIAL(key)) | 2895 if (!IS_SPECIAL(key)) |
2892 key = extract_modifiers(key, &modifiers); | 2896 key = extract_modifiers(key, &modifiers, |
2897 simplify, did_simplify); | |
2893 | 2898 |
2894 *modp = modifiers; | 2899 *modp = modifiers; |
2895 *srcp = end_of_name; | 2900 *srcp = end_of_name; |
2896 return key; | 2901 return key; |
2897 } | 2902 } |
2901 } | 2906 } |
2902 | 2907 |
2903 /* | 2908 /* |
2904 * Try to include modifiers in the key. | 2909 * Try to include modifiers in the key. |
2905 * Changes "Shift-a" to 'A', "Alt-A" to 0xc0, etc. | 2910 * Changes "Shift-a" to 'A', "Alt-A" to 0xc0, etc. |
2906 */ | 2911 * When "simplify" is FALSE don't do Ctrl and Alt. |
2907 int | 2912 * When "simplify" is TRUE and Ctrl or Alt is removed from modifiers set |
2908 extract_modifiers(int key, int *modp) | 2913 * "did_simplify" when it's not NULL. |
2914 */ | |
2915 int | |
2916 extract_modifiers(int key, int *modp, int simplify, int *did_simplify) | |
2909 { | 2917 { |
2910 int modifiers = *modp; | 2918 int modifiers = *modp; |
2911 | 2919 |
2912 #ifdef MACOS_X | 2920 #ifdef MACOS_X |
2913 /* Command-key really special, no fancynest */ | 2921 // Command-key really special, no fancynest |
2914 if (!(modifiers & MOD_MASK_CMD)) | 2922 if (!(modifiers & MOD_MASK_CMD)) |
2915 #endif | 2923 #endif |
2916 if ((modifiers & MOD_MASK_SHIFT) && ASCII_ISALPHA(key)) | 2924 if ((modifiers & MOD_MASK_SHIFT) && ASCII_ISALPHA(key)) |
2917 { | 2925 { |
2918 key = TOUPPER_ASC(key); | 2926 key = TOUPPER_ASC(key); |
2919 modifiers &= ~MOD_MASK_SHIFT; | 2927 // With <C-S-a> and <A-S-a> we keep the shift modifier. |
2920 } | 2928 // With <S-a> and <S-A> we don't keep the shift modifier. |
2921 if ((modifiers & MOD_MASK_CTRL) | 2929 if (simplify || modifiers == MOD_MASK_SHIFT) |
2930 modifiers &= ~MOD_MASK_SHIFT; | |
2931 } | |
2932 | |
2933 // <C-H> and <C-h> mean the same thing, always use "H" | |
2934 if ((modifiers & MOD_MASK_CTRL) && ASCII_ISALPHA(key)) | |
2935 key = TOUPPER_ASC(key); | |
2936 | |
2937 if (simplify && (modifiers & MOD_MASK_CTRL) | |
2922 #ifdef EBCDIC | 2938 #ifdef EBCDIC |
2923 /* * TODO: EBCDIC Better use: | 2939 // TODO: EBCDIC Better use: |
2924 * && (Ctrl_chr(key) || key == '?') | 2940 // && (Ctrl_chr(key) || key == '?') |
2925 * ??? */ | 2941 // ??? |
2926 && strchr("?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_", key) | 2942 && strchr("?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_", key) |
2927 != NULL | 2943 != NULL |
2928 #else | 2944 #else |
2929 && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key)) | 2945 && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key)) |
2930 #endif | 2946 #endif |
2933 key = Ctrl_chr(key); | 2949 key = Ctrl_chr(key); |
2934 modifiers &= ~MOD_MASK_CTRL; | 2950 modifiers &= ~MOD_MASK_CTRL; |
2935 /* <C-@> is <Nul> */ | 2951 /* <C-@> is <Nul> */ |
2936 if (key == 0) | 2952 if (key == 0) |
2937 key = K_ZERO; | 2953 key = K_ZERO; |
2938 } | 2954 if (did_simplify != NULL) |
2955 *did_simplify = TRUE; | |
2956 } | |
2957 | |
2939 #ifdef MACOS_X | 2958 #ifdef MACOS_X |
2940 /* Command-key really special, no fancynest */ | 2959 /* Command-key really special, no fancynest */ |
2941 if (!(modifiers & MOD_MASK_CMD)) | 2960 if (!(modifiers & MOD_MASK_CMD)) |
2942 #endif | 2961 #endif |
2943 if ((modifiers & MOD_MASK_ALT) && key < 0x80 | 2962 if (simplify && (modifiers & MOD_MASK_ALT) && key < 0x80 |
2944 && !enc_dbcs) // avoid creating a lead byte | 2963 && !enc_dbcs) // avoid creating a lead byte |
2945 { | 2964 { |
2946 key |= 0x80; | 2965 key |= 0x80; |
2947 modifiers &= ~MOD_MASK_ALT; /* remove the META modifier */ | 2966 modifiers &= ~MOD_MASK_ALT; /* remove the META modifier */ |
2967 if (did_simplify != NULL) | |
2968 *did_simplify = TRUE; | |
2948 } | 2969 } |
2949 | 2970 |
2950 *modp = modifiers; | 2971 *modp = modifiers; |
2951 return key; | 2972 return key; |
2952 } | 2973 } |