Mercurial > vim
comparison src/misc2.c @ 28668:53c608c7ea9e v8.2.4858
patch 8.2.4858: K_SPECIAL may be escaped twice
Commit: https://github.com/vim/vim/commit/db08887f24d20be11d184ce321bc0890613e42bd
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon May 2 22:53:45 2022 +0100
patch 8.2.4858: K_SPECIAL may be escaped twice
Problem: K_SPECIAL may be escaped twice.
Solution: Avoid double escaping. (closes https://github.com/vim/vim/issues/10340)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 03 May 2022 00:00:04 +0200 |
parents | ce202d2984a0 |
children | d770568e6c98 |
comparison
equal
deleted
inserted
replaced
28667:7782b07d29ca | 28668:53c608c7ea9e |
---|---|
1263 int | 1263 int |
1264 trans_special( | 1264 trans_special( |
1265 char_u **srcp, | 1265 char_u **srcp, |
1266 char_u *dst, | 1266 char_u *dst, |
1267 int flags, // FSK_ values | 1267 int flags, // FSK_ values |
1268 int escape_ks, // escape K_SPECIAL bytes in the character | |
1268 int *did_simplify) // FSK_SIMPLIFY and found <C-H> or <A-x> | 1269 int *did_simplify) // FSK_SIMPLIFY and found <C-H> or <A-x> |
1269 { | 1270 { |
1270 int modifiers = 0; | 1271 int modifiers = 0; |
1271 int key; | 1272 int key; |
1272 | 1273 |
1273 key = find_special_key(srcp, &modifiers, flags, did_simplify); | 1274 key = find_special_key(srcp, &modifiers, flags, did_simplify); |
1274 if (key == 0) | 1275 if (key == 0) |
1275 return 0; | 1276 return 0; |
1276 | 1277 |
1277 return special_to_buf(key, modifiers, flags & FSK_KEYCODE, dst); | 1278 return special_to_buf(key, modifiers, escape_ks, dst); |
1278 } | 1279 } |
1279 | 1280 |
1280 /* | 1281 /* |
1281 * Put the character sequence for "key" with "modifiers" into "dst" and return | 1282 * Put the character sequence for "key" with "modifiers" into "dst" and return |
1282 * the resulting length. | 1283 * the resulting length. |
1283 * When "keycode" is TRUE prefer key code, e.g. K_DEL instead of DEL. | 1284 * When "escape_ks" is TRUE escape K_SPECIAL bytes in the character. |
1284 * The sequence is not NUL terminated. | 1285 * The sequence is not NUL terminated. |
1285 * This is how characters in a string are encoded. | 1286 * This is how characters in a string are encoded. |
1286 */ | 1287 */ |
1287 int | 1288 int |
1288 special_to_buf(int key, int modifiers, int keycode, char_u *dst) | 1289 special_to_buf(int key, int modifiers, int escape_ks, char_u *dst) |
1289 { | 1290 { |
1290 int dlen = 0; | 1291 int dlen = 0; |
1291 | 1292 |
1292 // Put the appropriate modifier in a string | 1293 // Put the appropriate modifier in a string |
1293 if (modifiers != 0) | 1294 if (modifiers != 0) |
1301 { | 1302 { |
1302 dst[dlen++] = K_SPECIAL; | 1303 dst[dlen++] = K_SPECIAL; |
1303 dst[dlen++] = KEY2TERMCAP0(key); | 1304 dst[dlen++] = KEY2TERMCAP0(key); |
1304 dst[dlen++] = KEY2TERMCAP1(key); | 1305 dst[dlen++] = KEY2TERMCAP1(key); |
1305 } | 1306 } |
1306 else if (has_mbyte && !keycode) | 1307 else if (escape_ks) |
1308 dlen = (int)(add_char2buf(key, dst + dlen) - dst); | |
1309 else if (has_mbyte) | |
1307 dlen += (*mb_char2bytes)(key, dst + dlen); | 1310 dlen += (*mb_char2bytes)(key, dst + dlen); |
1308 else if (keycode) | |
1309 dlen = (int)(add_char2buf(key, dst + dlen) - dst); | |
1310 else | 1311 else |
1311 dst[dlen++] = key; | 1312 dst[dlen++] = key; |
1312 | 1313 |
1313 return dlen; | 1314 return dlen; |
1314 } | 1315 } |