Skip to content

Commit 1ceb778

Browse files
committed
fixup oob error
1 parent fd2cf07 commit 1ceb778

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

lua/neocrush/highlight.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ function M.flash_range(bufnr, start_line, end_line)
3333

3434
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
3535

36-
for line = start_line, end_line - 1 do
37-
vim.api.nvim_buf_set_extmark(bufnr, ns, line, 0, {
38-
end_row = line,
39-
end_col = 0,
40-
hl_group = config.highlight_group,
41-
hl_eol = true,
42-
line_hl_group = config.highlight_group,
43-
})
36+
local line_count = vim.api.nvim_buf_line_count(bufnr)
37+
local clamped_end = math.min(end_line, line_count)
38+
39+
for line = start_line, clamped_end - 1 do
40+
if line >= 0 and line < line_count then
41+
vim.api.nvim_buf_set_extmark(bufnr, ns, line, 0, {
42+
end_row = line,
43+
end_col = 0,
44+
hl_group = config.highlight_group,
45+
hl_eol = true,
46+
line_hl_group = config.highlight_group,
47+
})
48+
end
4449
end
4550

4651
vim.defer_fn(function()

0 commit comments

Comments
 (0)