diff options
-rw-r--r-- | src/nvim/normal.c | 6 | ||||
-rw-r--r-- | src/nvim/ops.c | 5 | ||||
-rw-r--r-- | test/functional/clipboard/clipboard_provider_spec.lua | 53 | ||||
-rw-r--r-- | test/functional/fixtures/autoload/provider/clipboard.vim (renamed from test/functional/clipboard/autoload/provider/clipboard.vim) | 4 |
4 files changed, 66 insertions, 2 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index a5eb54bb68..95e1c3d113 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2016,6 +2016,9 @@ do_mouse ( if (regname == '.') insert_reg(regname, true); else { + if (regname == 0 && eval_has_provider("clipboard")) { + regname = '*'; + } if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) insert_reg(regname, true); else { @@ -2279,6 +2282,9 @@ do_mouse ( * Middle mouse click: Put text before cursor. */ if (which_button == MOUSE_MIDDLE) { + if (regname == 0 && eval_has_provider("clipboard")) { + regname = '*'; + } if (yank_register_mline(regname)) { if (mouse_past_bottom) dir = FORWARD; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 063ad154f1..8a7ced138b 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -765,7 +765,10 @@ yankreg_T *get_yank_register(int regname, int mode) if (mode == YREG_PASTE && get_clipboard(regname, ®, false)) { // reg is set to clipboard contents. return reg; - } else if (mode != YREG_YANK && (regname == 0 || regname == '"') && y_previous != NULL) { + } else if (mode != YREG_YANK + && (regname == 0 || regname == '"' || regname == '*' || regname == '+') + && y_previous != NULL) { + // in case clipboard not available, paste from previous used register return y_previous; } diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index 9282a66240..f6d6188d82 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -92,7 +92,7 @@ end) describe('clipboard usage', function() before_each(function() clear() - execute('let &rtp = "test/functional/clipboard,".&rtp') + execute('let &rtp = "test/functional/fixtures,".&rtp') execute('call getreg("*")') -- force load of provider end) @@ -197,6 +197,17 @@ describe('clipboard usage', function() expect('some more') end) + it('pastes unnamed register if the provider fails', function() + insert('the text') + feed('yy') + execute("let g:cliperror = 1") + feed('"*p') + expect([[ + the text + the text]]) + end) + + describe('with clipboard=unnamed', function() -- the basic behavior of unnamed register should be the same -- even when handled by clipboard provider @@ -261,6 +272,16 @@ describe('clipboard usage', function() expect("indeed star") end) + it('unamed operations work even if the provider fails', function() + insert('the text') + feed('yy') + execute("let g:cliperror = 1") + feed('p') + expect([[ + the text + the text]]) + end) + end) it('supports :put', function() @@ -335,4 +356,34 @@ describe('clipboard usage', function() 'Howdy!', }, 'v'}, eval("g:test_clip['*']")) end) + + it('handles middleclick correctly', function() + local screen = Screen.new(30, 5) + screen:attach() + insert([[ + the source + a target]]) + feed('gg"*ywwyw') + -- clicking depends on the exact visual layout, so expect it: + screen:expect([[ + the ^source | + a target | + ~ | + ~ | + | + ]], nil, {{bold = true, foreground = Screen.colors.Blue}}) + + feed('<MiddleMouse><0,1>') + expect([[ + the source + the a target]]) + + -- on error, fall back to unnamed register + execute("let g:cliperror = 1") + feed('<MiddleMouse><6,1>') + expect([[ + the source + the a sourcetarget]]) + end) + end) diff --git a/test/functional/clipboard/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim index d88b68464e..a28484169a 100644 --- a/test/functional/clipboard/autoload/provider/clipboard.vim +++ b/test/functional/fixtures/autoload/provider/clipboard.vim @@ -3,8 +3,12 @@ let g:test_clip = { '+': [''], '*': [''], } let s:methods = {} let g:cliplossy = 0 +let g:cliperror = 0 function! s:methods.get(reg) + if g:cliperror + return 0 + end if g:cliplossy " behave like pure text clipboard return g:test_clip[a:reg][0] |