Skip to content

Commit 40f33a8

Browse files
fix: Replace prompt guard timer with observer on opencode window focus
1 parent 6c4b737 commit 40f33a8

File tree

3 files changed

+2
-42
lines changed

3 files changed

+2
-42
lines changed

lua/opencode/ui/output_window.lua

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
local state = require('opencode.state')
22
local config = require('opencode.config')
3-
local Timer = require('opencode.ui.timer')
4-
local topbar = require('opencode.ui.topbar')
53

64
local M = {}
75
M.namespace = vim.api.nvim_create_namespace('opencode_output')
@@ -157,36 +155,6 @@ function M.setup_keymaps(windows)
157155
end
158156

159157
function M.setup_autocmds(windows, group)
160-
local guard_timer = nil
161-
162-
local function start_guard_timer()
163-
if guard_timer then
164-
return -- Timer already running
165-
end
166-
guard_timer = Timer.new({
167-
interval = 1000, -- 1 second
168-
repeat_timer = true,
169-
on_tick = function()
170-
if state.windows and vim.api.nvim_win_is_valid(state.windows.output_win) then
171-
topbar.render()
172-
return true
173-
end
174-
return false
175-
end,
176-
})
177-
guard_timer:start_and_tick()
178-
end
179-
180-
local function stop_guard_timer()
181-
if guard_timer then
182-
guard_timer:stop()
183-
guard_timer = nil
184-
end
185-
end
186-
187-
-- Start the timer when the window is created (visible) and tick immediately
188-
start_guard_timer()
189-
190158
vim.api.nvim_create_autocmd('WinEnter', {
191159
group = group,
192160
buffer = windows.output_buf,
@@ -207,15 +175,6 @@ function M.setup_autocmds(windows, group)
207175
end,
208176
})
209177

210-
-- Stop the timer when the window is closed
211-
vim.api.nvim_create_autocmd('WinClosed', {
212-
group = group,
213-
pattern = tostring(windows.output_win),
214-
callback = function()
215-
stop_guard_timer()
216-
end,
217-
})
218-
219178
state.subscribe('current_permission', function()
220179
require('opencode.keymap').toggle_permission_keymap(windows.output_buf)
221180
end)

lua/opencode/ui/prompt_guard_indicator.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local M = {}
22

3-
local state = require('opencode.state')
43
local config = require('opencode.config')
54
local util = require('opencode.util')
65
local icons = require('opencode.ui.icons')

lua/opencode/ui/topbar.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ function M.setup()
137137
state.subscribe('current_mode', on_change)
138138
state.subscribe('current_model', on_change)
139139
state.subscribe('active_session', on_change)
140+
state.subscribe('is_opencode_focused', on_change)
140141
M.render()
141142
end
142143

143144
function M.close()
144145
state.unsubscribe('current_mode', on_change)
145146
state.unsubscribe('current_model', on_change)
146147
state.unsubscribe('active_session', on_change)
148+
state.unsubscribe('is_opencode_focused', on_change)
147149
end
148150
return M

0 commit comments

Comments
 (0)