comparison src/getchar.c @ 26946:8d4b44cc324e v8.2.4002

patch 8.2.4002: first char typed in Select mode can be wrong Commit: https://github.com/vim/vim/commit/6cac77016b1636e04073e8348b7cee02259ef928 Author: zeertzjq <zeertzjq@outlook.com> Date: Tue Jan 4 18:01:21 2022 +0000 patch 8.2.4002: first char typed in Select mode can be wrong Problem: First char typed in Select mode can be wrong. Solution: Escape special bytes in the input buffer. (closes https://github.com/vim/vim/issues/9469)
author Bram Moolenaar <Bram@vim.org>
date Tue, 04 Jan 2022 19:15:04 +0100
parents 8dbdd68627bd
children 1a56c0252772
comparison
equal deleted inserted replaced
26945:69550041276c 26946:8d4b44cc324e
1119 * Returns the length of what was inserted. 1119 * Returns the length of what was inserted.
1120 */ 1120 */
1121 int 1121 int
1122 ins_char_typebuf(int c, int modifier) 1122 ins_char_typebuf(int c, int modifier)
1123 { 1123 {
1124 char_u buf[MB_MAXBYTES + 4]; 1124 char_u buf[MB_MAXBYTES * 3 + 4];
1125 int len = 0; 1125 int len = 0;
1126 1126
1127 if (modifier != 0) 1127 if (modifier != 0)
1128 { 1128 {
1129 buf[0] = K_SPECIAL; 1129 buf[0] = K_SPECIAL;
1140 buf[len + 3] = NUL; 1140 buf[len + 3] = NUL;
1141 len += 3; 1141 len += 3;
1142 } 1142 }
1143 else 1143 else
1144 { 1144 {
1145 len += (*mb_char2bytes)(c, buf + len); 1145 char_u *p = buf + len;
1146 buf[len] = NUL; 1146 int char_len = (*mb_char2bytes)(c, p);
1147 #ifdef FEAT_GUI
1148 int save_gui_in_use = gui.in_use;
1149
1150 gui.in_use = FALSE;
1151 #endif
1152 // if the character contains CSI or K_SPECIAL bytes they need escaping
1153 len += fix_input_buffer(p, char_len);
1154 #ifdef FEAT_GUI
1155 gui.in_use = save_gui_in_use;
1156 #endif
1147 } 1157 }
1148 (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); 1158 (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
1149 return len; 1159 return len;
1150 } 1160 }
1151 1161
3642 if (gui.in_use && p[0] == CSI && i >= 2) 3652 if (gui.in_use && p[0] == CSI && i >= 2)
3643 { 3653 {
3644 p += 2; 3654 p += 2;
3645 i -= 2; 3655 i -= 2;
3646 } 3656 }
3647 # ifndef MSWIN
3648 // When the GUI is not used CSI needs to be escaped. 3657 // When the GUI is not used CSI needs to be escaped.
3649 else if (!gui.in_use && p[0] == CSI) 3658 else if (!gui.in_use && p[0] == CSI)
3650 { 3659 {
3651 mch_memmove(p + 3, p + 1, (size_t)i); 3660 mch_memmove(p + 3, p + 1, (size_t)i);
3652 *p++ = K_SPECIAL; 3661 *p++ = K_SPECIAL;
3653 *p++ = KS_EXTRA; 3662 *p++ = KS_EXTRA;
3654 *p = (int)KE_CSI; 3663 *p = (int)KE_CSI;
3655 len += 2; 3664 len += 2;
3656 } 3665 }
3657 # endif
3658 else 3666 else
3659 #endif 3667 #endif
3660 if (p[0] == NUL || (p[0] == K_SPECIAL 3668 if (p[0] == NUL || (p[0] == K_SPECIAL
3661 // timeout may generate K_CURSORHOLD 3669 // timeout may generate K_CURSORHOLD
3662 && (i < 2 || p[1] != KS_EXTRA || p[2] != (int)KE_CURSORHOLD) 3670 && (i < 2 || p[1] != KS_EXTRA || p[2] != (int)KE_CURSORHOLD)