diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-02-29 08:21:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 08:21:13 +0800 |
commit | f9e7c4c9c4fb89e6114a37387f3738d98cb4ba6a (patch) | |
tree | fa3310b4c83676e84ed7c579dcaba79001244faa /runtime/lua/vim | |
parent | ce7c51a1a3b2b38cdba730aeb53840d0ace32173 (diff) | |
download | rneovim-f9e7c4c9c4fb89e6114a37387f3738d98cb4ba6a.tar.gz rneovim-f9e7c4c9c4fb89e6114a37387f3738d98cb4ba6a.tar.bz2 rneovim-f9e7c4c9c4fb89e6114a37387f3738d98cb4ba6a.zip |
refactor(defaults): use getregion() for Visual mode gx (#27663)
Also make it work better on a multiline selection.
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/_defaults.lua | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index c8131f8eb4..91baee1a1e 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -67,15 +67,6 @@ do ) --- Map |gx| to call |vim.ui.open| on the identifier under the cursor do - -- TODO: use vim.region() when it lands... #13896 #16843 - local function get_visual_selection() - local save_a = vim.fn.getreginfo('a') - vim.cmd([[norm! "ay]]) - local selection = vim.fn.getreg('a', 1) - vim.fn.setreg('a', save_a) - return selection - end - local function do_open(uri) local _, err = vim.ui.open(uri) if err then @@ -89,7 +80,10 @@ do do_open(vim.fn.expand('<cfile>')) end, { desc = gx_desc }) vim.keymap.set({ 'x' }, 'gx', function() - do_open(get_visual_selection()) + local lines = + vim.fn.getregion(vim.fn.getpos('.'), vim.fn.getpos('v'), { type = vim.fn.mode() }) + -- Trim whitespace on each line and concatenate. + do_open(table.concat(vim.iter(lines):map(vim.trim):totable())) end, { desc = gx_desc }) end end |