Skip to content

Commit 43a0af3

Browse files
committed
fix(renderer): no autoscroll on full session load
Noticed it was really slow loading a full session and traced it down to scrolling while loading a big session, specifically setting the cursor.
1 parent de2657a commit 43a0af3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lua/opencode/ui/renderer.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local M = {}
1010
M._subscriptions = {}
1111
M._prev_line_count = 0
1212
M._render_state = RenderState.new()
13+
M._disable_auto_scroll = false
1314

1415
local trigger_on_data_rendered = require('opencode.util').debounce(function()
1516
local cb_type = type(config.ui.on_data_rendered)
@@ -31,6 +32,7 @@ end, 250)
3132
function M.reset()
3233
M._prev_line_count = 0
3334
M._render_state:reset()
35+
M._disable_auto_scroll = false
3436

3537
output_window.clear()
3638

@@ -114,6 +116,10 @@ end
114116

115117
function M._render_full_session_data(session_data)
116118
M.reset()
119+
120+
-- disable auto-scroll, makes loading a full session much faster
121+
M._disable_auto_scroll = true
122+
117123
local revert_index = nil
118124

119125
for i, msg in ipairs(session_data) do
@@ -134,6 +140,9 @@ function M._render_full_session_data(session_data)
134140
if revert_index then
135141
M._write_formatted_data(formatter._format_revert_message(state.messages, revert_index))
136142
end
143+
144+
-- re-enable Auto-scroll
145+
M._disable_auto_scroll = false
137146
M._scroll_to_bottom()
138147
end
139148

@@ -161,6 +170,11 @@ end
161170
---Auto-scroll to bottom if user was already at bottom
162171
---Respects cursor position if user has scrolled up
163172
function M._scroll_to_bottom()
173+
-- if we're loading a full session, don't scroll incrementally
174+
if M._disable_auto_scroll then
175+
return
176+
end
177+
164178
local ok, line_count = pcall(vim.api.nvim_buf_line_count, state.windows.output_buf)
165179
if not ok then
166180
return

0 commit comments

Comments
 (0)