diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-01-25 16:18:58 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-01-25 16:18:58 +0800 |
commit | d11bbacf0ffa45096364195bda4739984d25121e (patch) | |
tree | ad1eba2f9daaec6c0e91830415ce1db445f83ec9 /src | |
parent | ecec957125ca95ef5fbc4534d62ed16cfedb0c44 (diff) | |
download | rneovim-d11bbacf0ffa45096364195bda4739984d25121e.tar.gz rneovim-d11bbacf0ffa45096364195bda4739984d25121e.tar.bz2 rneovim-d11bbacf0ffa45096364195bda4739984d25121e.zip |
fix(inccommand): do not change reg_prev_sub when previewing
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_cmds.c | 10 | ||||
-rw-r--r-- | src/nvim/regexp.c | 15 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 95390b1a70..66e9738f98 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3629,8 +3629,14 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle // We do it here once to avoid it to be replaced over and over again. // But don't do it when it starts with "\=", then it's an expression. assert(sub != NULL); + + bool sub_needs_free = false; if (!(sub[0] == '\\' && sub[1] == '=')) { + char_u *source = sub; sub = regtilde(sub, p_magic); + // When previewing, the new pattern allocated by regtilde() needs to be freed + // in this function because it will not be used or freed by regtilde() later. + sub_needs_free = preview && sub != source; } // Check for a match on each line. @@ -4425,6 +4431,10 @@ skip: kv_destroy(preview_lines.subresults); + if (sub_needs_free) { + xfree(sub); + } + return preview_buf; #undef ADJUST_SUB_FIRSTLNUM #undef PUSH_PREVIEW_LINES diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 45e580dbee..9bea54ad2c 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -6538,11 +6538,16 @@ char_u *regtilde(char_u *source, int magic) } } - xfree(reg_prev_sub); - if (newsub != source) /* newsub was allocated, just keep it */ - reg_prev_sub = newsub; - else /* no ~ found, need to save newsub */ - reg_prev_sub = vim_strsave(newsub); + // Only change reg_prev_sub when not previewing. + if (!(State & CMDPREVIEW)) { + xfree(reg_prev_sub); + if (newsub != source) { // newsub was allocated, just keep it + reg_prev_sub = newsub; + } else { // no ~ found, need to save newsub + reg_prev_sub = vim_strsave(newsub); + } + } + return newsub; } |