aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshadmansaleh <shadmansaleh3@gmail.com>2021-06-18 15:03:12 +0600
committershadmansaleh <shadmansaleh3@gmail.com>2021-07-01 15:01:01 +0600
commit21444552c06240b68fd1ad2c3be4e83f64a10882 (patch)
tree2ea1457b5579bdd90be4664f0aa5d54e3024c342
parentf35a5f2efc32b508ff5fc7d55b31a5bb7facfa17 (diff)
downloadrneovim-21444552c06240b68fd1ad2c3be4e83f64a10882.tar.gz
rneovim-21444552c06240b68fd1ad2c3be4e83f64a10882.tar.bz2
rneovim-21444552c06240b68fd1ad2c3be4e83f64a10882.zip
BugFix(clipboard): Fix block paste not working properly
Block copy and paste from system-clipboard currently breaks formatting. This fixes it. The bug occurs because system-clipboard doesn't contain information about what mode the copy was made. Simple solution to this is we keep a cache of copy we last made along with mode information. If system-clipboard returns the cache we apply the mode information that we know about that cache.
-rw-r--r--runtime/autoload/provider/clipboard.vim12
1 files changed, 11 insertions, 1 deletions
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index 07f37d604f..dea79f21f0 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -156,7 +156,14 @@ function! s:clipboard.get(reg) abort
elseif s:selections[a:reg].owner > 0
return s:selections[a:reg].data
end
- return s:try_cmd(s:paste[a:reg])
+
+ let clipboard_data = s:try_cmd(s:paste[a:reg])
+ if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0 && get(s:selections[a:reg].data, 0, []) == clipboard_data
+ " When system clipboard return is same as our cache return the cache
+ " as it contains regtype information
+ return s:selections[a:reg].data
+ end
+ return clipboard_data
endfunction
function! s:clipboard.set(lines, regtype, reg) abort
@@ -175,6 +182,9 @@ function! s:clipboard.set(lines, regtype, reg) abort
if s:cache_enabled == 0
call s:try_cmd(s:copy[a:reg], a:lines)
+ "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].data = [a:lines, a:regtype]
return 0
end