From 9c953962b4162aba81fc98bf8cdad2414085b356 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Tue, 7 Jul 2020 11:08:34 -0400 Subject: [PATCH] commit bash-20200706 snapshot --- CWRU/CWRU.chlog | 22 ++++++++++++++++++---- lib/readline/vi_mode.c | 27 +++++++++++++++++++++------ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 8c1f6a67..8f22677d 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -8653,12 +8653,26 @@ doc/{bash.1,bashref.texi} --- lib/readline/vi_mode.c - _rl_vi_done_inserting: make sure to close out all undo groups when - the insert performed by a `c' command finishes. Report and fix from - David Fries + leaving insert mode, so we don't have anything dangling. + Report and fix from David Fries 7/6 --- lib/readline/vi_mode.c - _rl_vi_domove_motion_cleanup: the `c' and `C' commands should enter - insert mode even if the motion command doesn't delete any text. From - a report by David Fries + insert mode even if the motion command doesn't delete any text. + From a report by David Fries + - _rl_vi_done_inserting: add a missing rl_end_undo_group when + _rl_vi_doing_insert is set: there should be one begun by + rl_vi_start_inserting and one begun by the command (change or replace). + From a report by David Fries + - rl_vi_replace: set _rl_vi_last_key_before_insert to 'R' explicitly, + since other code checks that and we want to allow users to rebind + this function + + 7/7 + --- +lib/readline/vi_mode.c + - rl_vi_{delete,change,yank}_to: if we have a non-null _rl_vimvcxt, + just reinitialize it so we don't have to allocate a new one. This is + a change primarily for callback mode, and fixes a memory leak diff --git a/lib/readline/vi_mode.c b/lib/readline/vi_mode.c index cecb981c..742341e3 100644 --- a/lib/readline/vi_mode.c +++ b/lib/readline/vi_mode.c @@ -875,8 +875,8 @@ _rl_vi_done_inserting (void) { if (_rl_vi_doing_insert) { - /* The `c', `s', and `S' commands set this. */ - rl_end_undo_group (); + /* The `c', `s', `S', and `R' commands set this. */ + rl_end_undo_group (); /* for the group in rl_vi_start_inserting */ /* Now, the text between rl_undo_list->next->start and rl_undo_list->next->end is what was inserted while in insert mode. It gets copied to VI_INSERT_BUFFER because it depends @@ -887,6 +887,9 @@ _rl_vi_done_inserting (void) _rl_vi_save_replace (); /* Half the battle */ else _rl_vi_save_insert (rl_undo_list->next); + /* sanity check, should always be >= 1 here */ + if (_rl_undo_group_level > 0) + rl_end_undo_group (); /* for the group in the command (change or replace) */ } else { @@ -900,6 +903,8 @@ _rl_vi_done_inserting (void) rl_end_undo_group (); } + /* Sanity check, make sure all the undo groups are closed before we leave + insert mode */ while (_rl_undo_group_level > 0) rl_end_undo_group (); } @@ -1385,7 +1390,11 @@ rl_vi_delete_to (int count, int key) { int c, r; - _rl_vimvcxt = _rl_mvcxt_alloc (VIM_DELETE, key); + if (_rl_vimvcxt) + _rl_mvcxt_init (_rl_vimvcxt, VIM_DELETE, key); + else + _rl_vimvcxt = _rl_mvcxt_alloc (VIM_DELETE, key); + _rl_vimvcxt->start = rl_point; rl_mark = rl_point; @@ -1473,7 +1482,10 @@ rl_vi_change_to (int count, int key) { int c, r; - _rl_vimvcxt = _rl_mvcxt_alloc (VIM_CHANGE, key); + if (_rl_vimvcxt) + _rl_mvcxt_init (_rl_vimvcxt, VIM_CHANGE, key); + else + _rl_vimvcxt = _rl_mvcxt_alloc (VIM_CHANGE, key); _rl_vimvcxt->start = rl_point; rl_mark = rl_point; @@ -1542,7 +1554,10 @@ rl_vi_yank_to (int count, int key) { int c, r; - _rl_vimvcxt = _rl_mvcxt_alloc (VIM_YANK, key); + if (_rl_vimvcxt) + _rl_mvcxt_init (_rl_vimvcxt, VIM_YANK, key); + else + _rl_vimvcxt = _rl_mvcxt_alloc (VIM_YANK, key); _rl_vimvcxt->start = rl_point; rl_mark = rl_point; @@ -2250,7 +2265,7 @@ rl_vi_replace (int count, int key) rl_vi_start_inserting (key, 1, rl_arg_sign); - _rl_vi_last_key_before_insert = key; + _rl_vi_last_key_before_insert = 'R'; /* in case someone rebinds it */ _rl_keymap = vi_replace_map; if (_rl_enable_bracketed_paste)