diff options
author | JD <46619169+rudiejd@users.noreply.github.com> | 2023-12-27 20:57:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-28 09:57:13 +0800 |
commit | 46ceefb52be6b014dd27b6adfbca3e1c9dff0c0c (patch) | |
tree | 34b795e7059f4e9eb08f8b0012e593189259b738 | |
parent | e0d998dbc8b8e7047e1cc2bb520aea4d0b34f726 (diff) | |
download | rneovim-46ceefb52be6b014dd27b6adfbca3e1c9dff0c0c.tar.gz rneovim-46ceefb52be6b014dd27b6adfbca3e1c9dff0c0c.tar.bz2 rneovim-46ceefb52be6b014dd27b6adfbca3e1c9dff0c0c.zip |
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.
-rw-r--r-- | src/nvim/ops.c | 10 | ||||
-rw-r--r-- | test/functional/provider/clipboard_spec.lua | 7 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8dc267cc45..4cce2e7ba6 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -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; } diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua index 3c2e358745..004ee6d106 100644 --- a/test/functional/provider/clipboard_spec.lua +++ b/test/functional/provider/clipboard_spec.lua @@ -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) |