Skip to content

Commit b0a3e0e

Browse files
committed
fix(renderer/buffer): include first line when slicing extmarks
1 parent af6100b commit b0a3e0e

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

lua/opencode/ui/renderer/buffer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ end
3838
local function slice_extmarks(extmarks, start_line)
3939
local slice = {}
4040
for line_idx, marks in pairs(extmarks or {}) do
41-
if line_idx >= start_line + 1 then
41+
if line_idx >= start_line then
4242
slice[line_idx - start_line] = vim.deepcopy(marks)
4343
end
4444
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local buffer = require('opencode.ui.renderer.buffer')
2+
local ctx = require('opencode.ui.renderer.ctx')
3+
local output_window = require('opencode.ui.output_window')
4+
local stub = require('luassert.stub')
5+
6+
describe('renderer.buffer extmarks', function()
7+
local set_lines_stub
8+
local clear_extmarks_stub
9+
local set_extmarks_stub
10+
local highlight_changed_lines_stub
11+
12+
before_each(function()
13+
ctx:reset()
14+
set_lines_stub = stub(output_window, 'set_lines')
15+
clear_extmarks_stub = stub(output_window, 'clear_extmarks')
16+
set_extmarks_stub = stub(output_window, 'set_extmarks')
17+
highlight_changed_lines_stub = stub(output_window, 'highlight_changed_lines')
18+
end)
19+
20+
after_each(function()
21+
set_lines_stub:revert()
22+
clear_extmarks_stub:revert()
23+
set_extmarks_stub:revert()
24+
highlight_changed_lines_stub:revert()
25+
ctx:reset()
26+
end)
27+
28+
it('reapplies extmarks on the first changed line when updating a part', function()
29+
ctx.render_state:set_part({ id = 'part_1', messageID = 'msg_1', type = 'text' }, 10, 11)
30+
31+
buffer.upsert_part_now('part_1', 'msg_1', {
32+
lines = { 'alpha', 'gamma' },
33+
extmarks = {
34+
[1] = {
35+
{ line_hl_group = 'OpencodeReasoningText' },
36+
},
37+
},
38+
actions = {},
39+
}, {
40+
lines = { 'alpha', 'beta' },
41+
extmarks = {},
42+
actions = {},
43+
})
44+
45+
assert.stub(clear_extmarks_stub).was_called_with(11, 12)
46+
assert.stub(set_extmarks_stub).was_called_with({
47+
[0] = {
48+
{ line_hl_group = 'OpencodeReasoningText' },
49+
},
50+
}, 11)
51+
end)
52+
end)

0 commit comments

Comments
 (0)