nvim-telescope / telescope-live-grep-args.nvim

Live grep with args
726 stars 40 forks source link

Visual selection doesn't work when selecting from end to start #63

Closed eyalk11 closed 10 months ago

eyalk11 commented 1 year ago

If you start from the end and extend the visual selection, your script gets confused,

E5108: Error executing lua: ...rep-args.nvim/lua/telescope-live-grep-args/shortcuts.lua:49: start_col must be less than end_col
stack traceback:
    [C]: in function 'get_visual'
    ...rep-args.nvim/lua/telescope-live-grep-args/shortcuts.lua:49: in function <...rep-args.nvim/lua/telescope-live-grep-args/shortcuts.lua:48>
eyalk11 commented 1 year ago

Fix (thanks chatgpt)

local function get_visual()
  local _, ls, cs = unpack(vim.fn.getpos('v'))
  local _, le, ce = unpack(vim.fn.getpos('.'))

  if ls > le or (ls == le and cs > ce) then
  ls, cs, le, ce = le, ce, ls, cs
    end

  return vim.api.nvim_buf_get_text(0, ls - 1, cs - 1, le - 1, ce, {})
end
ajenkinski commented 1 year ago

I just ran into this bug myself and came here to report it.

I fixed it locally like this:

local function get_visual()
  local _, ls, cs = unpack(vim.fn.getpos('v'))
  local _, le, ce = unpack(vim.fn.getpos('.'))

  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, {})
end
weeman1337 commented 10 months ago

Fixed by https://github.com/nvim-telescope/telescope-live-grep-args.nvim/pull/69