Mercurial > vim
comparison src/getchar.c @ 20571:5995db0fe84a v8.2.0839
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Commit: https://github.com/vim/vim/commit/b42c0d54279b1fdb79652db0c84171e213458809
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 29 22:41:41 2020 +0200
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Problem: Dropping modifier when putting a character back in typeahead.
Solution: Add modifier to ins_char_typebuf(). (closes https://github.com/vim/vim/issues/6158)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 29 May 2020 22:45:05 +0200 |
parents | a5a24d688e11 |
children | 3609e842f822 |
comparison
equal
deleted
inserted
replaced
20570:c08ee6345092 | 20571:5995db0fe84a |
---|---|
1099 * Can be used for a character obtained by vgetc() that needs to be put back. | 1099 * Can be used for a character obtained by vgetc() that needs to be put back. |
1100 * Uses cmd_silent, KeyTyped and KeyNoremap to restore the flags belonging to | 1100 * Uses cmd_silent, KeyTyped and KeyNoremap to restore the flags belonging to |
1101 * the char. | 1101 * the char. |
1102 */ | 1102 */ |
1103 void | 1103 void |
1104 ins_char_typebuf(int c) | 1104 ins_char_typebuf(int c, int modifier) |
1105 { | 1105 { |
1106 char_u buf[MB_MAXBYTES + 1]; | 1106 char_u buf[MB_MAXBYTES + 4]; |
1107 int idx = 0; | |
1108 | |
1109 if (modifier != 0) | |
1110 { | |
1111 buf[0] = K_SPECIAL; | |
1112 buf[1] = KS_MODIFIER; | |
1113 buf[2] = modifier; | |
1114 buf[3] = NUL; | |
1115 idx = 3; | |
1116 } | |
1107 if (IS_SPECIAL(c)) | 1117 if (IS_SPECIAL(c)) |
1108 { | 1118 { |
1109 buf[0] = K_SPECIAL; | 1119 buf[idx] = K_SPECIAL; |
1110 buf[1] = K_SECOND(c); | 1120 buf[idx + 1] = K_SECOND(c); |
1111 buf[2] = K_THIRD(c); | 1121 buf[idx + 2] = K_THIRD(c); |
1112 buf[3] = NUL; | 1122 buf[idx + 3] = NUL; |
1123 idx += 3; | |
1113 } | 1124 } |
1114 else | 1125 else |
1115 buf[(*mb_char2bytes)(c, buf)] = NUL; | 1126 buf[(*mb_char2bytes)(c, buf + idx) + idx] = NUL; |
1116 (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); | 1127 (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); |
1117 } | 1128 } |
1118 | 1129 |
1119 /* | 1130 /* |
1120 * Return TRUE if the typeahead buffer was changed (while waiting for a | 1131 * Return TRUE if the typeahead buffer was changed (while waiting for a |
1638 mouse_row = old_mouse_row; | 1649 mouse_row = old_mouse_row; |
1639 mouse_col = old_mouse_col; | 1650 mouse_col = old_mouse_col; |
1640 } | 1651 } |
1641 else | 1652 else |
1642 { | 1653 { |
1643 mod_mask = 0x0; | 1654 mod_mask = 0; |
1655 vgetc_mod_mask = 0; | |
1656 vgetc_char = 0; | |
1644 last_recorded_len = 0; | 1657 last_recorded_len = 0; |
1658 | |
1645 for (;;) // this is done twice if there are modifiers | 1659 for (;;) // this is done twice if there are modifiers |
1646 { | 1660 { |
1647 int did_inc = FALSE; | 1661 int did_inc = FALSE; |
1648 | 1662 |
1649 if (mod_mask | 1663 if (mod_mask |
1833 --no_mapping; | 1847 --no_mapping; |
1834 c = (*mb_ptr2char)(buf); | 1848 c = (*mb_ptr2char)(buf); |
1835 } | 1849 } |
1836 | 1850 |
1837 if (!no_reduce_keys) | 1851 if (!no_reduce_keys) |
1852 { | |
1838 // A modifier was not used for a mapping, apply it to ASCII | 1853 // A modifier was not used for a mapping, apply it to ASCII |
1839 // keys. Shift would already have been applied. | 1854 // keys. Shift would already have been applied. |
1855 // Remember the character and mod_mask from before, in some | |
1856 // cases they are put back in the typeahead buffer. | |
1857 vgetc_mod_mask = mod_mask; | |
1858 vgetc_char = c; | |
1840 c = merge_modifyOtherKeys(c); | 1859 c = merge_modifyOtherKeys(c); |
1860 } | |
1841 | 1861 |
1842 break; | 1862 break; |
1843 } | 1863 } |
1844 } | 1864 } |
1845 | 1865 |
2190 may_garbage_collect = save_may_garbage_collect; | 2210 may_garbage_collect = save_may_garbage_collect; |
2191 | 2211 |
2192 // If the current window or buffer changed we need to bail out of the | 2212 // If the current window or buffer changed we need to bail out of the |
2193 // waiting loop. E.g. when a job exit callback closes the terminal window. | 2213 // waiting loop. E.g. when a job exit callback closes the terminal window. |
2194 if (curwin->w_id != old_curwin_id || curbuf->b_fnum != old_curbuf_fnum) | 2214 if (curwin->w_id != old_curwin_id || curbuf->b_fnum != old_curbuf_fnum) |
2195 ins_char_typebuf(K_IGNORE); | 2215 ins_char_typebuf(K_IGNORE, 0); |
2196 | 2216 |
2197 --entered; | 2217 --entered; |
2198 } | 2218 } |
2199 #endif | 2219 #endif |
2200 | 2220 |