@@ -349,20 +349,16 @@ function M._render_full_session_data(session_data, opts)
349349 local visible_messages , hidden_count = get_visible_session_messages (state .messages )
350350 local revert_index = get_revert_index (state .messages )
351351
352- -- Lazy-render: only render viewport-sized message count.
353- -- Active when ctx.lazy_render_count is set or opts.lazy=true.
354- if lazy_limit == nil and opts .lazy then
355- local initial = get_initial_render_count ()
356- if # visible_messages > initial then
357- lazy_limit = initial
352+ if lazy_limit == nil then
353+ local initial = get_initial_render_count ()
354+ if # visible_messages > initial then
355+ lazy_limit = initial
356+ end
357+ end
358+ ctx .lazy_render_count = lazy_limit
359+ if lazy_limit and # visible_messages > lazy_limit then
360+ visible_messages = vim .list_slice (visible_messages , # visible_messages - lazy_limit + 1 )
358361 end
359- end
360- -- Persist back to ctx so it survives the next M.reset()
361- ctx .lazy_render_count = lazy_limit
362- if lazy_limit and # visible_messages > lazy_limit then
363- hidden_count = hidden_count + (# visible_messages - lazy_limit )
364- visible_messages = vim .list_slice (visible_messages , # visible_messages - lazy_limit + 1 )
365- end
366362
367363 local t_format_start = vim .uv .hrtime ()
368364 flush .begin_bulk_mode ()
@@ -435,10 +431,9 @@ function M.render_from_cache(session_data)
435431 if not output_window .mounted () or not state .api_client then
436432 return
437433 end
438- M ._render_full_session_data (session_data , {
439- restore_model_from_messages = true ,
440- lazy = ctx .lazy_render_count ~= nil ,
441- })
434+ M ._render_full_session_data (session_data , {
435+ restore_model_from_messages = true ,
436+ })
442437 local active_session = state .active_session
443438 if active_session and active_session .id then
444439 require (' opencode.ui.question_window' ).restore_pending_question (active_session .id )
@@ -468,17 +463,38 @@ function M.load_more_messages()
468463 return true
469464end
470465
466+ --- Load all remaining messages and re-render.
467+ --- Used when user explicitly navigates to the top (gg) to ensure
468+ --- the full history is available for navigation and search.
469+ --- @return boolean Whether any messages were loaded
470+ function M .load_all_messages ()
471+ if not state .messages then
472+ return false
473+ end
474+ local total = # get_visible_session_messages (state .messages )
475+ if total == 0 then
476+ return false
477+ end
478+ local current = ctx .lazy_render_count or 0
479+ if current >= total then
480+ return false
481+ end
482+
483+ ctx .lazy_render_count = total
484+ M .render_from_cache (state .messages )
485+ return true
486+ end
487+
471488--- Fetch the active session from the server and render it
472489--- @return Promise<OpencodeMessage[]>
473490function M .render_full_session ()
474491 if not output_window .mounted () or not state .api_client then
475492 return Promise .new ():resolve (nil )
476493 end
477494 return fetch_session ():and_then (function (session_data )
478- M ._render_full_session_data (session_data , {
479- restore_model_from_messages = true ,
480- lazy = true ,
481- })
495+ M ._render_full_session_data (session_data , {
496+ restore_model_from_messages = true ,
497+ })
482498 local active_session = state .active_session
483499 if active_session and active_session .id then
484500 require (' opencode.ui.question_window' ).restore_pending_question (active_session .id )
0 commit comments