File tree Expand file tree Collapse file tree 4 files changed +28
-1
lines changed
Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ function M.open(opts)
7474 elseif opts .focus == ' output' then
7575 ui .focus_output ({ restore_position = are_windows_closed })
7676 end
77+ state .is_opencode_focused = true
7778end
7879
7980--- Sends a message to the active session, creating one if necessary.
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ local config = require('opencode.config')
1111--- @class OpencodeState
1212--- @field windows OpencodeWindowState | nil
1313--- @field input_content table
14+ --- @field is_opencode_focused boolean
1415--- @field last_focused_opencode_window string | nil
1516--- @field last_input_window_position number | nil
1617--- @field last_output_window_position number | nil
@@ -46,6 +47,7 @@ local _state = {
4647 -- ui
4748 windows = nil , --- @type OpencodeWindowState
4849 input_content = {},
50+ is_opencode_focused = false ,
4951 last_focused_opencode_window = nil ,
5052 last_input_window_position = nil ,
5153 last_output_window_position = nil ,
Original file line number Diff line number Diff line change @@ -25,13 +25,21 @@ function M.setup_autocmds(windows)
2525 vim .api .nvim_create_autocmd (' WinLeave' , {
2626 group = group ,
2727 pattern = ' *' ,
28- callback = function ()
28+ callback = function (e )
2929 if not require (' opencode.ui.ui' ).is_opencode_focused () then
3030 require (' opencode.context' ).load ()
3131 require (' opencode.state' ).last_code_win_before_opencode = vim .api .nvim_get_current_win ()
3232 end
3333 end ,
3434 })
35+
36+ vim .api .nvim_create_autocmd (' WinEnter' , {
37+ group = group ,
38+ pattern = ' *' ,
39+ callback = function ()
40+ require (' opencode.state' ).is_opencode_focused = require (' opencode.ui.ui' ).is_opencode_focused ()
41+ end ,
42+ })
3543end
3644
3745function M .setup_resize_handler (windows )
Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ function M._setup_event_subscriptions(subscribe)
7878 state .event_manager [method ](state .event_manager , ' permission.replied' , M .on_permission_replied )
7979 state .event_manager [method ](state .event_manager , ' file.edited' , M .on_file_edited )
8080 state .event_manager [method ](state .event_manager , ' custom.restore_point.created' , M .on_restore_points )
81+
82+ state [method ](' is_opencode_focused' , M .on_focus_changed )
8183end
8284
8385--- Unsubscribe from local state and server subscriptions
@@ -696,6 +698,20 @@ function M._rerender_part(part_id)
696698 M ._replace_part_in_buffer (part_id , formatted )
697699end
698700
701+ --- Event handler for focus changes
702+ --- Re-renders part associated with current permission for displaying global shortcuts or buffer-local ones
703+ function M .on_focus_changed ()
704+ if not state .current_permission or not state .current_permission .callID then
705+ return
706+ end
707+
708+ local part_id = M ._find_part_by_call_id (state .current_permission .callID , state .current_permission .messageID )
709+ if part_id then
710+ M ._rerender_part (part_id )
711+ trigger_on_data_rendered ()
712+ end
713+ end
714+
699715--- Get all actions available at a specific line
700716--- @param line integer 1-indexed line number
701717--- @return table[] List of actions available at that line
You can’t perform that action at this time.
0 commit comments