mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #3014 'clipboard: handle middle-click paste correctly.'.
This commit is contained in:
commit
bd753bdacc
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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]
|
Loading…
Reference in New Issue
Block a user