diff --git a/CHANGELOG.md b/CHANGELOG.md index 0077b0c..50d4384 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lua/telescope-live-grep-args/shortcuts.lua b/lua/telescope-live-grep-args/shortcuts.lua index c37038e..4064660 100644 --- a/lua/telescope-live-grep-args/shortcuts.lua +++ b/lua/telescope-live-grep-args/shortcuts.lua @@ -8,6 +8,11 @@ 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, {}) end