Skip to content

Commit d56458c

Browse files
committed
fix(streaming_renderer): better way to shift part lines
Rather than iterating over the entire part cache, start from the most recent part in the most recent message and stop when it's lines are earlier than the change
1 parent 05dd0ff commit d56458c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

lua/opencode/ui/streaming_renderer.lua

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,34 @@ function M._shift_lines(from_line, delta)
7575
return
7676
end
7777

78-
vim.notify('Shifting lines from: ' .. from_line .. ' by delta: ' .. delta)
78+
local examined = 0
79+
local shifted = 0
7980

80-
for part_id, part_data in pairs(M._part_cache) do
81-
if part_data.line_start and part_data.line_start >= from_line then
82-
part_data.line_start = part_data.line_start + delta
83-
if part_data.line_end then
84-
part_data.line_end = part_data.line_end + delta
81+
for i = #state.messages, 1, -1 do
82+
local msg_wrapper = state.messages[i]
83+
if msg_wrapper.parts then
84+
for j = #msg_wrapper.parts, 1, -1 do
85+
local part = msg_wrapper.parts[j]
86+
if part.id then
87+
local part_data = M._part_cache[part.id]
88+
if part_data and part_data.line_start then
89+
examined = examined + 1
90+
if part_data.line_start < from_line then
91+
-- vim.notify('Shifting lines from: ' .. from_line .. ' by delta: ' .. delta .. ' examined: ' .. examined .. ' shifted: ' .. shifted)
92+
return
93+
end
94+
part_data.line_start = part_data.line_start + delta
95+
if part_data.line_end then
96+
part_data.line_end = part_data.line_end + delta
97+
end
98+
shifted = shifted + 1
99+
end
100+
end
85101
end
86102
end
87103
end
104+
105+
-- vim.notify('Shifting lines from: ' .. from_line .. ' by delta: ' .. delta .. ' examined: ' .. examined .. ' shifted: ' .. shifted)
88106
end
89107

90108
function M._apply_extmarks(buf, line_offset, extmarks)

0 commit comments

Comments
 (0)