comparison src/getchar.c @ 32369:ffbae151e462 v9.0.1516

patch 9.0.1516: cannot use special keys in <Cmd> mapping Commit: https://github.com/vim/vim/commit/3ab3a864814f903da8a158c01820e4fbe1013c08 Author: zeertzjq <zeertzjq@outlook.com> Date: Sat May 6 16:22:04 2023 +0100 patch 9.0.1516: cannot use special keys in <Cmd> mapping Problem: Cannot use special keys in <Cmd> mapping. Solution: Do allow for special keys in <Cmd> and <ScriptCmd> mappings. (closes #12326)
author Bram Moolenaar <Bram@vim.org>
date Sat, 06 May 2023 17:30:03 +0200
parents bea4ebf594c6
children 89679a3f2e09
comparison
equal deleted inserted replaced
32368:2992e4adb0da 32369:ffbae151e462
597 // CTRL-V '0' must be inserted as CTRL-V 048 597 // CTRL-V '0' must be inserted as CTRL-V 048
598 if (*s == NUL && c == '0') 598 if (*s == NUL && c == '0')
599 add_buff(&redobuff, (char_u *)"048", 3L); 599 add_buff(&redobuff, (char_u *)"048", 3L);
600 else 600 else
601 add_char_buff(&redobuff, c); 601 add_char_buff(&redobuff, c);
602 }
603 }
604
605 /*
606 * Append "s" to the redo buffer, leaving 3-byte special key codes unmodified
607 * and escaping other K_SPECIAL and CSI bytes.
608 */
609 void
610 AppendToRedobuffSpec(char_u *s)
611 {
612 while (*s != NUL)
613 {
614 if (*s == K_SPECIAL && s[1] != NUL && s[2] != NUL)
615 {
616 // insert special key literally
617 add_buff(&redobuff, s, 3L);
618 s += 3;
619 }
620 else
621 add_char_buff(&redobuff, mb_cptr2char_adv(&s));
602 } 622 }
603 } 623 }
604 624
605 /* 625 /*
606 * Append a character to the redo buffer. 626 * Append a character to the redo buffer.
3939 // that might be the start of an escape sequence. Convert it back 3959 // that might be the start of an escape sequence. Convert it back
3940 // to a single Esc here. 3960 // to a single Esc here.
3941 if (c1 == K_ESC) 3961 if (c1 == K_ESC)
3942 c1 = ESC; 3962 c1 = ESC;
3943 } 3963 }
3944 if (c1 == Ctrl_V)
3945 {
3946 // CTRL-V is followed by octal, hex or other characters, reverses
3947 // what AppendToRedobuffLit() does.
3948 ++no_reduce_keys; // don't merge modifyOtherKeys
3949 c1 = get_literal(TRUE);
3950 --no_reduce_keys;
3951 }
3952 3964
3953 if (got_int) 3965 if (got_int)
3954 aborted = TRUE; 3966 aborted = TRUE;
3955 else if (c1 == '\r' || c1 == '\n') 3967 else if (c1 == '\r' || c1 == '\n')
3956 c1 = NUL; // end the line 3968 c1 = NUL; // end the line
3960 { 3972 {
3961 // give a nicer error message for this special case 3973 // give a nicer error message for this special case
3962 emsg(_(e_cmd_mapping_must_end_with_cr_before_second_cmd)); 3974 emsg(_(e_cmd_mapping_must_end_with_cr_before_second_cmd));
3963 aborted = TRUE; 3975 aborted = TRUE;
3964 } 3976 }
3965 else if (IS_SPECIAL(c1)) 3977 else if (c1 == K_SNR)
3966 { 3978 {
3967 if (c1 == K_SNR) 3979 ga_concat(&line_ga, (char_u *)"<SNR>");
3968 ga_concat(&line_ga, (char_u *)"<SNR>"); 3980 }
3981 else
3982 {
3983 if (cmod != 0)
3984 {
3985 ga_append(&line_ga, K_SPECIAL);
3986 ga_append(&line_ga, KS_MODIFIER);
3987 ga_append(&line_ga, cmod);
3988 }
3989 if (IS_SPECIAL(c1))
3990 {
3991 ga_append(&line_ga, K_SPECIAL);
3992 ga_append(&line_ga, K_SECOND(c1));
3993 ga_append(&line_ga, K_THIRD(c1));
3994 }
3969 else 3995 else
3970 { 3996 ga_append(&line_ga, c1);
3971 semsg(e_cmd_mapping_must_not_include_str_key, 3997 }
3972 get_special_key_name(c1, cmod));
3973 aborted = TRUE;
3974 }
3975 }
3976 else
3977 ga_append(&line_ga, c1);
3978 3998
3979 cmod = 0; 3999 cmod = 0;
3980 } 4000 }
3981 4001
3982 no_mapping--; 4002 no_mapping--;