Skip to content

Commit 84eb139

Browse files
committed
fix(renderer): part and message deletion
1 parent 4079c13 commit 84eb139

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lua/opencode/ui/renderer.lua

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,30 @@ function M._remove_part_from_buffer(part_id)
273273
return
274274
end
275275

276-
output_window.set_lines({}, cached.line_start, cached.line_end + 1)
276+
output_window.clear_extmarks(cached.line_start - 1, cached.line_end)
277+
output_window.set_lines({}, cached.line_start - 1, cached.line_end)
277278

278279
M._render_state:remove_part(part_id)
279280
end
280281

282+
---Remove message header from buffer and adjust subsequent line positions
283+
---@param message_id string Message ID
284+
function M._remove_message_from_buffer(message_id)
285+
local cached = M._render_state:get_message(message_id)
286+
if not cached or not cached.line_start or not cached.line_end then
287+
return
288+
end
289+
290+
if not state.windows or not state.windows.output_buf then
291+
return
292+
end
293+
294+
output_window.clear_extmarks(cached.line_start - 1, cached.line_end)
295+
output_window.set_lines({}, cached.line_start - 1, cached.line_end)
296+
297+
M._render_state:remove_message(message_id)
298+
end
299+
281300
---Event handler for message.updated events
282301
---Creates new message or updates existing message info
283302
---@param message {info: MessageInfo} Event properties
@@ -385,7 +404,6 @@ end
385404
---Event handler for message.part.removed events
386405
---@param properties {sessionID: string, messageID: string, partID: string} Event properties
387406
function M.on_part_removed(properties)
388-
--- WARN: this code is untested
389407
if not properties then
390408
return
391409
end
@@ -418,7 +436,6 @@ end
418436
---Removes message and all its parts from buffer
419437
---@param properties {sessionID: string, messageID: string} Event properties
420438
function M.on_message_removed(properties)
421-
--- WARN: this code is untested
422439
if not properties then
423440
return
424441
end
@@ -440,7 +457,7 @@ function M.on_message_removed(properties)
440457
end
441458
end
442459

443-
--- FIXME: remove part from render_state
460+
M._remove_message_from_buffer(message_id)
444461

445462
for i, msg in ipairs(state.messages) do
446463
if msg.info.id == message_id then

0 commit comments

Comments
 (0)