From 94a5f1e7d70c6562eb4d6e9766464c344a455fa2 Mon Sep 17 00:00:00 2001 From: ADoyle Date: Mon, 2 Sep 2024 15:46:14 +0800 Subject: [PATCH] fix: extra char when vim option 'selection' = exclusive When `:set selection=exclusive`, the returned value from `get_visual()` will contain an extra char. Use `vim.fn.getregion` which follows vim option 'selection' to fix this issue. --- lua/telescope-live-grep-args/shortcuts.lua | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lua/telescope-live-grep-args/shortcuts.lua b/lua/telescope-live-grep-args/shortcuts.lua index c67b1a3..737e6fe 100644 --- a/lua/telescope-live-grep-args/shortcuts.lua +++ b/lua/telescope-live-grep-args/shortcuts.lua @@ -6,14 +6,7 @@ local live_grep_args = require("telescope").extensions.live_grep_args local helpers = require("telescope-live-grep-args.helpers") local function get_visual() - local _, ls, cs = unpack(vim.fn.getpos("v")) - local _, le, ce = unpack(vim.fn.getpos(".")) - - -- nvim_buf_get_text requires start and end args be in correct order - ls, le = math.min(ls, le), math.max(ls, le) - cs, ce = math.min(cs, ce), math.max(cs, ce) - - return vim.api.nvim_buf_get_text(0, ls - 1, cs - 1, le - 1, ce, {}) + return vim.fn.getregion(vim.fn.getpos("v"), vim.fn.getpos(".")) end local grep_under_default_opts = {