diff options
-rw-r--r-- | runtime/autoload/provider/clipboard.vim | 14 | ||||
-rw-r--r-- | runtime/doc/options.txt | 4 | ||||
-rw-r--r-- | src/nvim/ops.c | 2 | ||||
-rw-r--r-- | test/functional/clipboard/clipboard_provider_spec.lua | 49 | ||||
-rw-r--r-- | test/functional/fixtures/autoload/provider/clipboard.vim | 12 |
5 files changed, 71 insertions, 10 deletions
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index d20b3a9bf1..5d1ce7896d 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -55,13 +55,21 @@ endif let s:clipboard = {} function! s:clipboard.get(reg) - if s:selections[a:reg].owner > 0 - return s:selections[a:reg].data + let reg = a:reg == '"' ? '+' : a:reg + if s:selections[reg].owner > 0 + return s:selections[reg].data end - return s:try_cmd(s:paste[a:reg]) + return s:try_cmd(s:paste[reg]) endfunction function! s:clipboard.set(lines, regtype, reg) + if a:reg == '"' + call s:clipboard.set(a:lines,a:regtype,'+') + if s:copy['*'] != s:copy['+'] + call s:clipboard.set(a:lines,a:regtype,'*') + end + return 0 + end if s:cache_enabled == 0 call s:try_cmd(s:copy[a:reg], a:lines) return 0 diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index fea8a59a74..fe1e3d57a5 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1402,8 +1402,8 @@ A jump table for the options with a short description can be found at |Q_op|. register '*' for all yank, delete, change and put operations which would normally go to the unnamed register. When "unnamed" is also included to the - option, yank operations (but not delete, change or - put) will additionally copy the text into register + option, yank and delete operations (but not put) + will additionally copy the text into register '*'. See |nvim-clipboard|. < *clipboard-autoselect* diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d0f1f09223..766b5720d9 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5278,7 +5278,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet) } yankreg_T *target; if (cb_flags & CB_UNNAMEDPLUS) { - *name = '+'; + *name = cb_flags & CB_UNNAMED ? '"': '+'; target = &y_regs[PLUS_REGISTER]; } else { *name = '*'; diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index f6d6188d82..30903e8b57 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -232,12 +232,15 @@ describe('clipboard usage', function() expect('words') eq({{'words'}, 'v'}, eval("g:test_clip['*']")) + -- "+ shouldn't have changed + eq({''}, eval("g:test_clip['+']")) + execute("let g:test_clip['*'] = ['linewise stuff','']") feed('p') expect([[ words linewise stuff]]) - end) + end) it('does not clobber "0 when pasting', function() insert('a line') @@ -284,6 +287,50 @@ describe('clipboard usage', function() end) + describe('with clipboard=unnamedplus', function() + before_each(function() + execute('set clipboard=unnamedplus') + end) + + it('links the "+ and unnamed registers', function() + insert("one two") + feed('^"+dwdw"+P') + expect('two') + eq({{'two'}, 'v'}, eval("g:test_clip['+']")) + + -- "* shouldn't have changed + eq({''}, eval("g:test_clip['*']")) + + execute("let g:test_clip['+'] = ['three']") + feed('p') + expect('twothree') + end) + + it('and unnamed, yanks to both', function() + execute('set clipboard=unnamedplus,unnamed') + insert([[ + really unnamed + text]]) + feed('ggdd"*p"+p') + expect([[ + text + really unnamed + really unnamed]]) + eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['+']")) + eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['*']")) + + -- unnamedplus takes predecence when pasting + execute("let g:test_clip['+'] = ['the plus','']") + execute("let g:test_clip['*'] = ['the star','']") + feed("p") + expect([[ + text + really unnamed + really unnamed + the plus]]) + end) + end) + it('supports :put', function() insert("a line") execute("let g:test_clip['*'] = ['some text']") diff --git a/test/functional/fixtures/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim index a28484169a..0935ea45ff 100644 --- a/test/functional/fixtures/autoload/provider/clipboard.vim +++ b/test/functional/fixtures/autoload/provider/clipboard.vim @@ -9,16 +9,22 @@ function! s:methods.get(reg) if g:cliperror return 0 end + let reg = a:reg == '"' ? '+' : a:reg if g:cliplossy " behave like pure text clipboard - return g:test_clip[a:reg][0] + return g:test_clip[reg][0] else - "behave like VIMENC clipboard - return g:test_clip[a:reg] + " behave like VIMENC clipboard + return g:test_clip[reg] end endfunction function! s:methods.set(lines, regtype, reg) + if a:reg == '"' + call s:methods.set(a:lines,a:regtype,'+') + call s:methods.set(a:lines,a:regtype,'*') + return 0 + end let g:test_clip[a:reg] = [a:lines, a:regtype] endfunction |