Mercurial > vim
comparison src/getchar.c @ 28333:04310f81143d v8.2.4692
patch 8.2.4692: no test for what 8.2.4691 fixes
Commit: https://github.com/vim/vim/commit/0f68e6c07aaf62c034a242f183b93c1bb44e7f93
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue Apr 5 13:17:01 2022 +0100
patch 8.2.4692: no test for what 8.2.4691 fixes
Problem: No test for what 8.2.4691 fixes.
Solution: Add a test. Use a more generic sotlution. (closes https://github.com/vim/vim/issues/10090)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 05 Apr 2022 14:30:03 +0200 |
parents | 3e707d35d05d |
children | 390dfc3e409b |
comparison
equal
deleted
inserted
replaced
28332:609c7fb65969 | 28333:04310f81143d |
---|---|
1417 | 1417 |
1418 static int old_char = -1; // character put back by vungetc() | 1418 static int old_char = -1; // character put back by vungetc() |
1419 static int old_mod_mask; // mod_mask for ungotten character | 1419 static int old_mod_mask; // mod_mask for ungotten character |
1420 static int old_mouse_row; // mouse_row related to old_char | 1420 static int old_mouse_row; // mouse_row related to old_char |
1421 static int old_mouse_col; // mouse_col related to old_char | 1421 static int old_mouse_col; // mouse_col related to old_char |
1422 static int old_KeyStuffed; // whether old_char was stuffed | |
1423 | |
1424 static int can_get_old_char() | |
1425 { | |
1426 // If the old character was not stuffed and characters have been added to | |
1427 // the stuff buffer, need to first get the stuffed characters instead. | |
1428 return old_char != -1 && (old_KeyStuffed || stuff_empty()); | |
1429 } | |
1422 | 1430 |
1423 /* | 1431 /* |
1424 * Save all three kinds of typeahead, so that the user must type at a prompt. | 1432 * Save all three kinds of typeahead, so that the user must type at a prompt. |
1425 */ | 1433 */ |
1426 void | 1434 void |
1685 | 1693 |
1686 /* | 1694 /* |
1687 * If a character was put back with vungetc, it was already processed. | 1695 * If a character was put back with vungetc, it was already processed. |
1688 * Return it directly. | 1696 * Return it directly. |
1689 */ | 1697 */ |
1690 if (old_char != -1) | 1698 if (can_get_old_char()) |
1691 { | 1699 { |
1692 c = old_char; | 1700 c = old_char; |
1693 old_char = -1; | 1701 old_char = -1; |
1694 mod_mask = old_mod_mask; | 1702 mod_mask = old_mod_mask; |
1695 mouse_row = old_mouse_row; | 1703 mouse_row = old_mouse_row; |
1985 * Returns NUL if no character is available. | 1993 * Returns NUL if no character is available. |
1986 */ | 1994 */ |
1987 int | 1995 int |
1988 vpeekc(void) | 1996 vpeekc(void) |
1989 { | 1997 { |
1990 if (old_char != -1) | 1998 if (can_get_old_char()) |
1991 return old_char; | 1999 return old_char; |
1992 return vgetorpeek(FALSE); | 2000 return vgetorpeek(FALSE); |
1993 } | 2001 } |
1994 | 2002 |
1995 #if defined(FEAT_TERMRESPONSE) || defined(FEAT_TERMINAL) || defined(PROTO) | 2003 #if defined(FEAT_TERMRESPONSE) || defined(FEAT_TERMINAL) || defined(PROTO) |
2940 return map_result_nomatch; | 2948 return map_result_nomatch; |
2941 } | 2949 } |
2942 | 2950 |
2943 /* | 2951 /* |
2944 * unget one character (can only be done once!) | 2952 * unget one character (can only be done once!) |
2953 * If the character was stuffed, vgetc() will get it next time it was called. | |
2954 * Otherwise vgetc() will only get it when the stuff buffer is empty. | |
2945 */ | 2955 */ |
2946 void | 2956 void |
2947 vungetc(int c) | 2957 vungetc(int c) |
2948 { | 2958 { |
2949 old_char = c; | 2959 old_char = c; |
2950 old_mod_mask = mod_mask; | 2960 old_mod_mask = mod_mask; |
2951 old_mouse_row = mouse_row; | 2961 old_mouse_row = mouse_row; |
2952 old_mouse_col = mouse_col; | 2962 old_mouse_col = mouse_col; |
2963 old_KeyStuffed = KeyStuffed; | |
2953 } | 2964 } |
2954 | 2965 |
2955 /* | 2966 /* |
2956 * Get a byte: | 2967 * Get a byte: |
2957 * 1. from the stuffbuffer | 2968 * 1. from the stuffbuffer |
3753 garray_T line_ga; | 3764 garray_T line_ga; |
3754 int c1 = -1; | 3765 int c1 = -1; |
3755 int c2; | 3766 int c2; |
3756 int cmod = 0; | 3767 int cmod = 0; |
3757 int aborted = FALSE; | 3768 int aborted = FALSE; |
3758 int first = TRUE; | |
3759 int got_ctrl_o = FALSE; | |
3760 | 3769 |
3761 ga_init2(&line_ga, 1, 32); | 3770 ga_init2(&line_ga, 1, 32); |
3762 | 3771 |
3763 // no mapping for these characters | 3772 // no mapping for these characters |
3764 no_mapping++; | 3773 no_mapping++; |
3781 break; | 3790 break; |
3782 } | 3791 } |
3783 | 3792 |
3784 // Get one character at a time. | 3793 // Get one character at a time. |
3785 c1 = vgetorpeek(TRUE); | 3794 c1 = vgetorpeek(TRUE); |
3786 | |
3787 // do not use Ctrl_O at the start, stuff it back later | |
3788 if (first && c1 == Ctrl_O) | |
3789 { | |
3790 got_ctrl_o = TRUE; | |
3791 first = FALSE; | |
3792 continue; | |
3793 } | |
3794 first = FALSE; | |
3795 | 3795 |
3796 // Get two extra bytes for special keys | 3796 // Get two extra bytes for special keys |
3797 if (c1 == K_SPECIAL) | 3797 if (c1 == K_SPECIAL) |
3798 { | 3798 { |
3799 c1 = vgetorpeek(TRUE); | 3799 c1 = vgetorpeek(TRUE); |
3842 | 3842 |
3843 cmod = 0; | 3843 cmod = 0; |
3844 } | 3844 } |
3845 | 3845 |
3846 no_mapping--; | 3846 no_mapping--; |
3847 if (got_ctrl_o) | |
3848 stuffcharReadbuff(Ctrl_O); | |
3849 | 3847 |
3850 if (aborted) | 3848 if (aborted) |
3851 ga_clear(&line_ga); | 3849 ga_clear(&line_ga); |
3852 | 3850 |
3853 return (char_u *)line_ga.ga_data; | 3851 return (char_u *)line_ga.ga_data; |