Skip to content

Commit

Permalink
Fix get_visual argument order bug
Browse files Browse the repository at this point in the history
Ensure that the `start_row`, `start_col`, `end_row`, and `end_col` arguments to `nvim_buf_get_text`
are passed in the correct order regardless of the direction of the visual selection.  Previously,
if the end of the visual selection was before the start, `nvim_buf_get_text` would raise an error
saying "start_col must be less than end_col".
  • Loading branch information
ajenkinski authored and weeman1337 committed Dec 15, 2023
1 parent 851c099 commit f80248a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## UNRELEASED

### Fixed

- Visual selection now also works when selecting backwards

## 1.0.0 - 2023-08-28

### Added
Expand Down
9 changes: 7 additions & 2 deletions lua/telescope-live-grep-args/shortcuts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ 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("."))
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, {})
end

Expand Down

0 comments on commit f80248a

Please sign in to comment.