Skip to content

Commit de0e59f

Browse files
committed
fix(core/renderer): tune rerenders
on open, force a re-render if we're not setting a new session in renderer, reset with the session changes, only render session if new session isn't nil
1 parent b3b1ca5 commit de0e59f

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

lua/opencode/core.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,18 @@ function M.open(opts)
5454
state.active_session = nil
5555
state.last_sent_context = nil
5656
state.active_session = M.create_new_session()
57-
58-
-- FIXME: shouldn't need to clear_output here, setting the session should
59-
-- do that
60-
ui.clear_output()
6157
else
6258
if not state.active_session then
6359
state.active_session = session.get_last_workspace_session()
64-
end
65-
66-
if (are_windows_closed or ui.is_output_empty()) and not state.display_route then
60+
else
61+
-- active session already set so no event will fire, need to force a refresh
6762
ui.render_output(true)
68-
ui.scroll_to_bottom()
6963
end
64+
65+
-- if (are_windows_closed or ui.is_output_empty()) and not state.display_route then
66+
-- ui.render_output(true)
67+
-- ui.scroll_to_bottom()
68+
-- end
7069
end
7170

7271
if opts.focus == 'input' then

lua/opencode/ui/renderer.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ end
2828

2929
---Set up all subscriptions, for both local and server events
3030
function M.setup_subscriptions(_)
31-
M._subscriptions.active_session = function(_, _, old)
32-
if not old then
33-
return
31+
M._subscriptions.active_session = function(_, new, _)
32+
M.reset()
33+
if new then
34+
M.render_full_session()
3435
end
35-
M.render_full_session()
3636
end
3737
state.subscribe('active_session', M._subscriptions.active_session)
3838
M._setup_event_subscriptions()

tests/unit/core_spec.lua

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,8 @@ describe('opencode.core', function()
143143
it('handles new session properly', function()
144144
state.windows = nil
145145
state.active_session = { id = 'old-session' }
146-
147-
ui.clear_output:revert()
148-
local cleared = false
149-
stub(ui, 'clear_output').invokes(function()
150-
cleared = true
151-
end)
152-
153146
core.open({ new_session = true, focus = 'input' })
154147
assert.truthy(state.active_session)
155-
assert.is_true(cleared)
156-
ui.clear_output:revert()
157-
stub(ui, 'clear_output')
158148
end)
159149

160150
it('focuses the appropriate window', function()

0 commit comments

Comments
 (0)