diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2024-06-11 13:18:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 13:18:06 -0500 |
commit | 3ad977f01d97e84b576e6965c5c9e4f75c10cb35 (patch) | |
tree | 352ed37a4738a1f5a78f892c77817e9937d58a28 /test/functional/terminal/clipboard_spec.lua | |
parent | 39d8651283c0458c20b755d2140c8a3cb7b581c5 (diff) | |
download | rneovim-3ad977f01d97e84b576e6965c5c9e4f75c10cb35.tar.gz rneovim-3ad977f01d97e84b576e6965c5c9e4f75c10cb35.tar.bz2 rneovim-3ad977f01d97e84b576e6965c5c9e4f75c10cb35.zip |
feat(terminal): add support for copying with OSC 52 in embedded terminal (#29117)
When libvterm receives the OSC 52 escape sequence it ignores it because
Nvim does not set any selection callbacks. Install selection callbacks
that forward to the clipboard provider, so that setting the clipboard
with OSC 52 in the embedded terminal writes to the system clipboard
using the configured clipboard provider.
Diffstat (limited to 'test/functional/terminal/clipboard_spec.lua')
-rw-r--r-- | test/functional/terminal/clipboard_spec.lua | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/functional/terminal/clipboard_spec.lua b/test/functional/terminal/clipboard_spec.lua new file mode 100644 index 0000000000..4a1a0e29fd --- /dev/null +++ b/test/functional/terminal/clipboard_spec.lua @@ -0,0 +1,65 @@ +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local eq = t.eq +local retry = t.retry + +local clear = n.clear +local fn = n.fn +local testprg = n.testprg +local exec_lua = n.exec_lua +local eval = n.eval + +describe(':terminal', function() + before_each(function() + clear() + + exec_lua([[ + local function clipboard(reg, type) + if type == 'copy' then + return function(lines) + local data = table.concat(lines, '\n') + vim.g.clipboard_data = data + end + end + + if type == 'paste' then + return function() + error() + end + end + + error('invalid type: ' .. type) + end + + vim.g.clipboard = { + name = 'Test', + copy = { + ['+'] = clipboard('+', 'copy'), + ['*'] = clipboard('*', 'copy'), + }, + paste = { + ['+'] = clipboard('+', 'paste'), + ['*'] = clipboard('*', 'paste'), + }, + } + ]]) + end) + + it('can write to the system clipboard', function() + eq('Test', eval('g:clipboard.name')) + + local text = 'Hello, world! This is some\nexample text\nthat spans multiple\nlines' + local encoded = exec_lua('return vim.base64.encode(...)', text) + + local function osc52(arg) + return string.format('\027]52;;%s\027\\', arg) + end + + fn.termopen({ testprg('shell-test'), '-t', osc52(encoded) }) + + retry(nil, 1000, function() + eq(text, exec_lua([[ return vim.g.clipboard_data ]])) + end) + end) +end) |