mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
fix(shada): don't store empty replacement string
This commit is contained in:
@ -2417,19 +2417,21 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
|
||||
// Initialize substitute replacement string
|
||||
SubReplacementString sub;
|
||||
sub_get_replacement(&sub);
|
||||
wms->replacement = (PossiblyFreedShadaEntry) {
|
||||
.can_free_entry = false,
|
||||
.data = {
|
||||
.type = kSDItemSubString,
|
||||
.timestamp = sub.timestamp,
|
||||
if (sub.sub != NULL) { // Don't store empty replacement string
|
||||
wms->replacement = (PossiblyFreedShadaEntry) {
|
||||
.can_free_entry = false,
|
||||
.data = {
|
||||
.sub_string = {
|
||||
.sub = sub.sub,
|
||||
}
|
||||
},
|
||||
.additional_data = sub.additional_data,
|
||||
}
|
||||
};
|
||||
.type = kSDItemSubString,
|
||||
.timestamp = sub.timestamp,
|
||||
.data = {
|
||||
.sub_string = {
|
||||
.sub = sub.sub,
|
||||
}
|
||||
},
|
||||
.additional_data = sub.additional_data,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize global marks
|
||||
|
@ -239,9 +239,10 @@ describe('ShaDa support code', function()
|
||||
nvim_command('silent! /«/')
|
||||
expect_exit(nvim_command, 'qall!')
|
||||
reset()
|
||||
fn.setline('.', { '\171«' })
|
||||
nvim_command('~&')
|
||||
eq('\171', fn.getline('.'))
|
||||
fn.setline('.', { 'foo', '\171«' })
|
||||
nvim_feed('gg0n')
|
||||
eq({ 0, 2, 2, 0 }, fn.getpos('.'))
|
||||
eq('\171«', fn.getline('.'))
|
||||
eq('', fn.histget('/', -1))
|
||||
end)
|
||||
|
||||
@ -250,9 +251,10 @@ describe('ShaDa support code', function()
|
||||
nvim_command('silent! /\171/')
|
||||
expect_exit(nvim_command, 'qall!')
|
||||
reset()
|
||||
fn.setline('.', { '\171«' })
|
||||
nvim_command('~&')
|
||||
eq('«', fn.getline('.'))
|
||||
fn.setline('.', { 'foo', '\171«' })
|
||||
nvim_feed('gg0n')
|
||||
eq({ 0, 2, 1, 0 }, fn.getpos('.'))
|
||||
eq('\171«', fn.getline('.'))
|
||||
eq('', fn.histget('/', -1))
|
||||
end)
|
||||
|
||||
@ -277,4 +279,14 @@ describe('ShaDa support code', function()
|
||||
nvim_command('wshada')
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
it('does not dump empty replacement string', function()
|
||||
expect_exit(nvim_command, 'qall!')
|
||||
reset()
|
||||
fn.setline('.', { 'foo', 'bar' })
|
||||
nvim_command('language C')
|
||||
nvim_feed('/f\n')
|
||||
local err = pcall_err(nvim_command, '~&')
|
||||
eq('Vim(~):E33: No previous substitute regular expression', err)
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user