mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-03 17:24:29 +00:00 
			
		
		
		
	fix(clipboard): enable cache for function providers #34470
Problem:
With these settings, copy/pasting `blockwise-visual` (with `CTRL+V`)
incorrectly pastes as a `linewise` mode because `regtype` is ignored:
    vim.opt.clipboard = 'unnamedplus'
    vim.g.clipboard = 'osc52'
To reproduce: press `CTRL+V` and select some characters press `p` and
observe that it is pasted in `linewise` mode.
Solution:
Enable the [clipboard.vim](https://github.com/neovim/neovim/blob/master/runtime/autoload/provider/clipboard.vim#L281-L283))
cache for function providers, so that `regtype` is maintained for the OSC52
clipboard provider.
			
			
This commit is contained in:
		@@ -268,13 +268,11 @@ function! provider#clipboard#Executable() abort
 | 
				
			|||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! s:clipboard.get(reg) abort
 | 
					function! s:clipboard.get(reg) abort
 | 
				
			||||||
  if type(s:paste[a:reg]) == v:t_func
 | 
					  if s:selections[a:reg].owner > 0
 | 
				
			||||||
    return s:paste[a:reg]()
 | 
					 | 
				
			||||||
  elseif s:selections[a:reg].owner > 0
 | 
					 | 
				
			||||||
    return s:selections[a:reg].data
 | 
					    return s:selections[a:reg].data
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let clipboard_data = s:try_cmd(s:paste[a:reg])
 | 
					  let clipboard_data = type(s:paste[a:reg]) == v:t_func ? s:paste[a:reg]() : s:try_cmd(s:paste[a:reg])
 | 
				
			||||||
  if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0
 | 
					  if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0
 | 
				
			||||||
        \ && type(clipboard_data) == v:t_list
 | 
					        \ && type(clipboard_data) == v:t_list
 | 
				
			||||||
        \ && get(s:selections[a:reg].data, 0, []) ==# clipboard_data
 | 
					        \ && get(s:selections[a:reg].data, 0, []) ==# clipboard_data
 | 
				
			||||||
@@ -294,13 +292,12 @@ function! s:clipboard.set(lines, regtype, reg) abort
 | 
				
			|||||||
    return 0
 | 
					    return 0
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if s:cache_enabled == 0 || type(s:copy[a:reg]) == v:t_func
 | 
				
			||||||
    if type(s:copy[a:reg]) == v:t_func
 | 
					    if type(s:copy[a:reg]) == v:t_func
 | 
				
			||||||
      call s:copy[a:reg](a:lines, a:regtype)
 | 
					      call s:copy[a:reg](a:lines, a:regtype)
 | 
				
			||||||
    return 0
 | 
					    else
 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if s:cache_enabled == 0
 | 
					 | 
				
			||||||
      call s:try_cmd(s:copy[a:reg], a:lines)
 | 
					      call s:try_cmd(s:copy[a:reg], a:lines)
 | 
				
			||||||
 | 
					    endif
 | 
				
			||||||
    "Cache it anyway we can compare it later to get regtype of the yank
 | 
					    "Cache it anyway we can compare it later to get regtype of the yank
 | 
				
			||||||
    let s:selections[a:reg] = copy(s:selection)
 | 
					    let s:selections[a:reg] = copy(s:selection)
 | 
				
			||||||
    let s:selections[a:reg].data = [a:lines, a:regtype]
 | 
					    let s:selections[a:reg].data = [a:lines, a:regtype]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user