Skip to content

Commit c41badb

Browse files
committed
patch 8.2.2961: keys typed during a :normal command are discarded
Problem: Keys typed during a :normal command are discarded. Solution: Concatenate saved typeahead and typed kesy. (closes #8340)
1 parent 8cf02e5 commit c41badb

File tree

8 files changed

+23
-10
lines changed

8 files changed

+23
-10
lines changed

src/debugger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ do_debug(char_u *cmd)
140140

141141
if (typeahead_saved)
142142
{
143-
restore_typeahead(&typeaheadbuf);
143+
restore_typeahead(&typeaheadbuf, TRUE);
144144
ignore_script = save_ignore_script;
145145
}
146146
ex_normal_busy = save_ex_normal_busy;

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5873,7 +5873,7 @@ f_inputrestore(typval_T *argvars UNUSED, typval_T *rettv)
58735873
{
58745874
--ga_userinput.ga_len;
58755875
restore_typeahead((tasave_T *)(ga_userinput.ga_data)
5876-
+ ga_userinput.ga_len);
5876+
+ ga_userinput.ga_len, TRUE);
58775877
// default return is zero == OK
58785878
}
58795879
else if (p_verbose > 1)

src/ex_docmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8249,7 +8249,7 @@ save_current_state(save_state_T *sst)
82498249
restore_current_state(save_state_T *sst)
82508250
{
82518251
// Restore the previous typeahead.
8252-
restore_typeahead(&sst->tabuf);
8252+
restore_typeahead(&sst->tabuf, FALSE);
82538253

82548254
msg_scroll = sst->save_msg_scroll;
82558255
restart_edit = sst->save_restart_edit;

src/getchar.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,9 +1414,10 @@ save_typeahead(tasave_T *tp)
14141414
/*
14151415
* Restore the typeahead to what it was before calling save_typeahead().
14161416
* The allocated memory is freed, can only be called once!
1417+
* When "overwrite" is FALSE input typed later is kept.
14171418
*/
14181419
void
1419-
restore_typeahead(tasave_T *tp)
1420+
restore_typeahead(tasave_T *tp, int overwrite UNUSED)
14201421
{
14211422
if (tp->typebuf_valid)
14221423
{
@@ -1432,7 +1433,7 @@ restore_typeahead(tasave_T *tp)
14321433
free_buff(&readbuf2);
14331434
readbuf2 = tp->save_readbuf2;
14341435
# ifdef USE_INPUT_BUF
1435-
set_input_buf(tp->save_inputbuf);
1436+
set_input_buf(tp->save_inputbuf, overwrite);
14361437
# endif
14371438
}
14381439

src/proto/getchar.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int typebuf_maplen(void);
3232
void del_typebuf(int len, int offset);
3333
int save_typebuf(void);
3434
void save_typeahead(tasave_T *tp);
35-
void restore_typeahead(tasave_T *tp);
35+
void restore_typeahead(tasave_T *tp, int overwrite);
3636
void openscript(char_u *name, int directly);
3737
void close_all_scripts(void);
3838
int using_script(void);

src/proto/ui.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int vim_is_input_buf_empty(void);
1919
int vim_free_in_input_buf(void);
2020
int vim_used_in_input_buf(void);
2121
char_u *get_input_buf(void);
22-
void set_input_buf(char_u *p);
22+
void set_input_buf(char_u *p, int overwrite);
2323
void add_to_input_buf(char_u *s, int len);
2424
void add_to_input_buf_csi(char_u *str, int len);
2525
void trash_input_buf(void);

src/ui.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,18 +810,28 @@ get_input_buf(void)
810810
/*
811811
* Restore the input buffer with a pointer returned from get_input_buf().
812812
* The allocated memory is freed, this only works once!
813+
* When "overwrite" is FALSE input typed later is kept.
813814
*/
814815
void
815-
set_input_buf(char_u *p)
816+
set_input_buf(char_u *p, int overwrite)
816817
{
817818
garray_T *gap = (garray_T *)p;
818819

819820
if (gap != NULL)
820821
{
821822
if (gap->ga_data != NULL)
822823
{
823-
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
824-
inbufcount = gap->ga_len;
824+
if (overwrite || inbufcount + gap->ga_len >= INBUFLEN)
825+
{
826+
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
827+
inbufcount = gap->ga_len;
828+
}
829+
else
830+
{
831+
mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount);
832+
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
833+
inbufcount += gap->ga_len;
834+
}
825835
vim_free(gap->ga_data);
826836
}
827837
vim_free(gap);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2961,
753755
/**/
754756
2960,
755757
/**/

0 commit comments

Comments
 (0)