From 3c948ac98548951d8d308308e7a09cb4b6015e22 Mon Sep 17 00:00:00 2001 From: Jonathan Apodaca Date: Wed, 16 Oct 2024 08:05:13 -0600 Subject: [PATCH] (bug) indicies past EOL should not error --- Makefile | 2 +- lua/tt/range.lua | 1 - spec/range_spec.lua | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ecc5b5b..386fc81 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ fmt: stylua . test: $(PLENARY_DIR) - nvim -u NORC --headless -c 'set packpath+=~/.local/share/nvim/site' -c 'packadd plenary.nvim' -c "PlenaryBustedDirectory spec/" + NVIM_APPNAME=noplugstest nvim -u NORC --headless -c 'set packpath+=~/.local/share/nvim/site' -c 'packadd plenary.nvim' -c "PlenaryBustedDirectory spec/" $(PLENARY_DIR): git clone https://github.com/nvim-lua/plenary.nvim/ $(PLENARY_DIR) diff --git a/lua/tt/range.lua b/lua/tt/range.lua index 04311e2..4fc0e50 100644 --- a/lua/tt/range.lua +++ b/lua/tt/range.lua @@ -352,7 +352,6 @@ function Range:replace(replacement) -- Fixup the bounds: local last_line = vim.api.nvim_buf_get_lines(self.stop.buf, self.stop.lnum, self.stop.lnum + 1, false)[1] or '' local max_col = #last_line - if last_line ~= '' then max_col = max_col + 1 end vim.api.nvim_buf_set_text( self.start.buf, diff --git a/spec/range_spec.lua b/spec/range_spec.lua index c1bd063..8b42ae6 100644 --- a/spec/range_spec.lua +++ b/spec/range_spec.lua @@ -455,4 +455,20 @@ describe('Range', function() assert.are.same(Pos.from_pos '.', Pos.new(nil, 1, 11)) end) end) + + it('selections set to past the EOL should not error', function() + withbuf({ 'Rg SET NAMES' }, function() + local b = vim.api.nvim_get_current_buf() + local r = Range.new(Pos.new(b, 0, 3), Pos.new(b, 0, 12), 'v') + r:replace 'bleh' + assert.are.same({ 'Rg bleh' }, vim.api.nvim_buf_get_lines(b, 0, -1, false)) + end) + + withbuf({ 'Rg SET NAMES' }, function() + local b = vim.api.nvim_get_current_buf() + local r = Range.new(Pos.new(b, 0, 3), Pos.new(b, 0, 11), 'v') + r:replace 'bleh' + assert.are.same({ 'Rg bleh' }, vim.api.nvim_buf_get_lines(b, 0, -1, false)) + end) + end) end)