Skip to content

Commit 4ae5d45

Browse files
committed
fix(output_window): avoid shifting folds when inserting at their boundary
shift_folds previously used >= which moved fold ranges that started or ended exactly at the insertion line. This caused folds to expand when inserting after their end. Use strict '>' comparisons and add a unit test to ensure folds remain unchanged when inserting after a fold's end. This should fix questions not displaying at the end of a fold
1 parent a3e114d commit 4ae5d45

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lua/opencode/ui/output_window.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,13 @@ function M.shift_folds(start_line, delta)
399399
end
400400

401401
for _, range in ipairs(folds) do
402-
if range.from >= start_line then
402+
if range.from > start_line then
403403
range.from = range.from + delta
404404
if delta < 0 then
405405
range.from = math.max(start_line, range.from)
406406
end
407407
end
408-
if range.to >= start_line then
408+
if range.to > start_line then
409409
range.to = range.to + delta
410410
if delta < 0 then
411411
range.to = math.max(start_line, range.to)

tests/unit/output_window_spec.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ describe('output_window.setup', function()
164164

165165
assert.equals(1, foldclosed)
166166
end)
167+
168+
it('does not expand a fold when inserting after its end', function()
169+
output_window.setup({ output_buf = buf, output_win = win })
170+
output_window.set_folds({ { from = 1, to = 3 } })
171+
172+
output_window.shift_folds(3, 4)
173+
174+
local folds = vim.api.nvim_buf_get_var(buf, 'opencode_folds')
175+
assert.same({ { from = 1, to = 3 } }, folds)
176+
end)
167177
end)
168178

169179
describe('output_window extmarks', function()

0 commit comments

Comments
 (0)