refactor: pass "preview" to regtilde()

This commit is contained in:
zeertzjq 2022-04-04 11:39:12 +08:00
parent 6486983117
commit bbfc44e255
3 changed files with 7 additions and 8 deletions

View File

@ -3642,7 +3642,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle
sub_copy = sub;
} else {
char_u *source = sub;
sub = regtilde(sub, p_magic);
sub = regtilde(sub, p_magic, preview);
// 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;
@ -4420,6 +4420,9 @@ skip:
vim_regfree(regmatch.regprog);
xfree(sub_copy);
if (sub_needs_free) {
xfree(sub);
}
// Restore the flag values, they can be used for ":&&".
subflags.do_all = save_do_all;
@ -4452,10 +4455,6 @@ skip:
kv_destroy(preview_lines.subresults);
if (sub_needs_free) {
xfree(sub);
}
return preview_buf;
#undef ADJUST_SUB_FIRSTLNUM
#undef PUSH_PREVIEW_LINES

View File

@ -1531,7 +1531,7 @@ static fptr_T do_Lower(int *d, int c)
*
* The tildes are parsed once before the first call to vim_regsub().
*/
char_u *regtilde(char_u *source, int magic)
char_u *regtilde(char_u *source, int magic, bool preview)
{
char_u *newsub = source;
char_u *tmpsub;
@ -1576,7 +1576,7 @@ char_u *regtilde(char_u *source, int magic)
}
// Only change reg_prev_sub when not previewing.
if (!(State & CMDPREVIEW)) {
if (!preview) {
xfree(reg_prev_sub);
if (newsub != source) { // newsub was allocated, just keep it
reg_prev_sub = newsub;

View File

@ -1238,7 +1238,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
// string is close to useless: you can only use it with :& or :~ and
// thats all because s//~ is not available until the first call to
// regtilde. Vim was not calling this for some reason.
(void)(char *)regtilde((char_u *)cur_entry.data.sub_string.sub, p_magic);
(void)(char *)regtilde((char_u *)cur_entry.data.sub_string.sub, p_magic, false);
// Do not free shada entry: its allocated memory was saved above.
break;
case kSDItemHistoryEntry: