Skip to content

Commit 3eb419b

Browse files
committed
fix: stop autoscroll when navigating output window
This should fix sudo-tee#39
1 parent 375a936 commit 3eb419b

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lua/opencode/core.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function M.select_session(parent_id)
2727
if state.windows then
2828
state.restore_points = {}
2929
ui.render_output(true)
30-
ui.scroll_to_bottom()
3130
ui.focus_input()
31+
ui.scroll_to_bottom()
3232
else
3333
M.open()
3434
end
@@ -139,7 +139,6 @@ end
139139
function M.after_run(prompt)
140140
context.unload_attachments()
141141
state.last_sent_context = vim.deepcopy(context.context)
142-
ui.focus_output()
143142
require('opencode.history').write(prompt)
144143

145144
if state.windows then

lua/opencode/ui/output_renderer.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ M.render = vim.schedule_wrap(function(windows, force_refresh)
146146

147147
if output_changed or force_refresh then
148148
vim.schedule(function()
149-
M.handle_auto_scroll(windows)
150149
M.render_markdown()
150+
M.handle_auto_scroll(windows)
151151
require('opencode.ui.topbar').render()
152152
end)
153153
end
@@ -246,12 +246,18 @@ function M.handle_auto_scroll(windows)
246246
end
247247

248248
local botline = vim.fn.line('w$', windows.output_win)
249+
local cursor_pos = vim.fn.getcurpos(windows.output_win)
250+
local is_focused = vim.api.nvim_get_current_win() == windows.output_win
249251

250252
local prev_line_count = vim.b[windows.output_buf].prev_line_count or 0
251253
vim.b[windows.output_buf].prev_line_count = line_count
252254

253255
local was_at_bottom = (botline >= prev_line_count) or prev_line_count == 0
254256

257+
if is_focused and cursor_pos[2] < prev_line_count - 1 then
258+
return
259+
end
260+
255261
if was_at_bottom then
256262
require('opencode.ui.ui').scroll_to_bottom()
257263
end

0 commit comments

Comments
 (0)