mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
fix(clipboard): make getreg() accurate for clipboard registers (#26740)
Problem: getreg("*") / getreg("+") disagree with :registers. Solution: Avoid falling back to unnamed register if provider fails.
This commit is contained in:
parent
e0d998dbc8
commit
46ceefb52b
@ -815,9 +815,15 @@ yankreg_T *get_yank_register(int regname, int mode)
|
||||
{
|
||||
yankreg_T *reg;
|
||||
|
||||
if (mode == YREG_PASTE && get_clipboard(regname, ®, false)) {
|
||||
if ((mode == YREG_PASTE || mode == YREG_PUT)
|
||||
&& get_clipboard(regname, ®, false)) {
|
||||
// reg is set to clipboard contents.
|
||||
return reg;
|
||||
} else if (mode == YREG_PUT && (regname == '*' || regname == '+')) {
|
||||
// in case clipboard not available and we aren't actually pasting,
|
||||
// return an empty register
|
||||
static yankreg_T empty_reg = { .y_array = NULL };
|
||||
return &empty_reg;
|
||||
} else if (mode != YREG_YANK
|
||||
&& (regname == 0 || regname == '"' || regname == '*' || regname == '+')
|
||||
&& y_previous != NULL) {
|
||||
@ -4893,7 +4899,7 @@ void *get_reg_contents(int regname, int flags)
|
||||
return get_reg_wrap_one_line(xstrdup(retval), flags);
|
||||
}
|
||||
|
||||
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
||||
yankreg_T *reg = get_yank_register(regname, YREG_PUT);
|
||||
if (reg->y_array == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -752,4 +752,11 @@ describe('clipboard (with fake clipboard.vim)', function()
|
||||
expect('some some')
|
||||
eq('some', eval('getreg("*")'))
|
||||
end)
|
||||
|
||||
it('does not fall back to unnamed register with getreg() #24257', function ()
|
||||
eval('setreg("", "wrong")')
|
||||
command('let g:cliperror = 1')
|
||||
eq('', eval('getreg("*")'))
|
||||
eq('', eval('getreg("+")'))
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user