Skip to content

Commit 69fcb75

Browse files
refactor: Move output_at_bottom boolean from state to output_window
1 parent 999fd73 commit 69fcb75

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

lua/opencode/state.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
---@field last_input_window_position integer[]|nil
1515
---@field last_output_window_position integer[]|nil
1616
---@field last_code_win_before_opencode integer|nil
17-
---@field output_window_at_bottom boolean
1817
---@field current_code_buf number|nil
1918
---@field display_route any|nil
2019
---@field current_mode string
@@ -56,7 +55,6 @@ local _state = {
5655
last_focused_opencode_window = nil,
5756
last_input_window_position = nil,
5857
last_output_window_position = nil,
59-
output_window_at_bottom = true,
6058
last_code_win_before_opencode = nil,
6159
current_code_buf = nil,
6260
display_route = nil,

lua/opencode/ui/output_window.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local config = require('opencode.config')
33

44
local M = {}
55
M.namespace = vim.api.nvim_create_namespace('opencode_output')
6+
M.viewport_at_bottom = true
67

78
function M.create_buf()
89
local output_buf = vim.api.nvim_create_buf(false, true)
@@ -215,7 +216,7 @@ function M.setup_autocmds(windows, group)
215216
buffer = windows.output_buf,
216217
callback = function()
217218
-- Update state to track if user is at bottom
218-
state.output_window_at_bottom = M.is_at_bottom(windows.output_win)
219+
M.viewport_at_bottom = M.is_at_bottom(windows.output_win)
219220
end,
220221
})
221222
end
@@ -225,6 +226,7 @@ function M.clear()
225226
-- clear extmarks in all namespaces as I've seen RenderMarkdown leave some
226227
-- extmarks behind
227228
M.clear_extmarks(0, -1, true)
229+
M.viewport_at_bottom = true
228230
end
229231

230232
return M

lua/opencode/ui/renderer.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ function M.reset()
5151
end
5252
state.current_permission = nil
5353

54-
-- Reset scroll state when session changes
55-
state.output_window_at_bottom = true
56-
5754
trigger_on_data_rendered()
5855
end
5956

@@ -242,16 +239,16 @@ function M.scroll_to_bottom()
242239
if prev_line_count == 0 then
243240
should_scroll = true
244241
-- Scroll if user is at bottom (respects manual scroll position)
245-
elseif state.output_window_at_bottom then
242+
elseif output_window.viewport_at_bottom then
246243
should_scroll = true
247244
end
248245

249246
if should_scroll then
250247
vim.api.nvim_win_set_cursor(state.windows.output_win, { line_count, 0 })
251-
state.output_window_at_bottom = true
248+
output_window.viewport_at_bottom = true
252249
else
253250
-- User has scrolled up, don't scroll
254-
state.output_window_at_bottom = false
251+
output_window.viewport_at_bottom = false
255252
end
256253
end
257254

0 commit comments

Comments
 (0)