mirror of
https://github.com/Myzel394/jsonfly.nvim.git
synced 2025-06-18 12:15:25 +02:00
fix: Improve edge case where file lines is shorter than BUFFER_SIZE
This commit is contained in:
parent
1c2fe2b24c
commit
65cdbb3283
@ -132,7 +132,14 @@ local function add_comma(buffer, insertion_line)
|
|||||||
|
|
||||||
-- Find next non-empty character in reverse
|
-- Find next non-empty character in reverse
|
||||||
for ii=insertion_line, 0, -BUFFER_SIZE do
|
for ii=insertion_line, 0, -BUFFER_SIZE do
|
||||||
local previous_lines = vim.api.nvim_buf_get_lines(buffer, ii - BUFFER_SIZE, ii, false)
|
local previous_lines = vim.api.nvim_buf_get_lines(
|
||||||
|
buffer,
|
||||||
|
math.max(0, ii - BUFFER_SIZE),
|
||||||
|
ii,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
print("previous lins: " .. vim.inspect(previous_lines))
|
||||||
|
|
||||||
if #previous_lines == 0 then
|
if #previous_lines == 0 then
|
||||||
return
|
return
|
||||||
@ -150,12 +157,12 @@ local function add_comma(buffer, insertion_line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Insert comma at position
|
-- Insert comma at position
|
||||||
local line_number = ii - (BUFFER_SIZE - jj)
|
local line_number = math.max(0, ii - BUFFER_SIZE) + jj - 1
|
||||||
vim.api.nvim_buf_set_text(
|
vim.api.nvim_buf_set_text(
|
||||||
buffer,
|
buffer,
|
||||||
line_number - 1,
|
line_number,
|
||||||
char_index,
|
char_index,
|
||||||
line_number - 1,
|
line_number,
|
||||||
char_index,
|
char_index,
|
||||||
{","}
|
{","}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user