Skip to content

Commit 57b7917

Browse files
committed
feat(output_window): avoid redundant fold updates and fix fold shifting
1 parent 16ea44c commit 57b7917

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

lua/opencode/ui/output_window.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ function M.set_folds(fold_ranges)
331331
local folds = fold_ranges or {}
332332
local buf = windows.output_buf
333333
local win = windows.output_win
334+
335+
local ok, prev_folds = pcall(vim.api.nvim_buf_get_var, buf, 'opencode_folds')
336+
if ok and vim.deep_equal(prev_folds, folds) then
337+
return
338+
end
339+
334340
vim.api.nvim_buf_set_var(buf, 'opencode_folds', folds)
335341

336342
if win and vim.api.nvim_win_is_valid(win) and vim.api.nvim_win_get_buf(win) == buf then
@@ -357,7 +363,18 @@ function M.shift_folds(start_line, delta)
357363
for _, range in ipairs(folds) do
358364
if range.from >= start_line then
359365
range.from = range.from + delta
366+
if delta < 0 then
367+
range.from = math.max(start_line, range.from)
368+
end
369+
end
370+
if range.to >= start_line then
360371
range.to = range.to + delta
372+
if delta < 0 then
373+
range.to = math.max(start_line, range.to)
374+
end
375+
end
376+
if range.to < range.from then
377+
range.to = range.from
361378
end
362379
end
363380
end

0 commit comments

Comments
 (0)