From 3f8b6d07ba086fa6a2aa6832d73933b934b92ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 11 Feb 2025 04:36:38 +0100 Subject: [PATCH] feat(sidebar): add member function to check whether the sidebar is focused (#1216) --- lua/avante/sidebar.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index a450dac..f70f6d2 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1257,6 +1257,20 @@ function Sidebar:initialize() return self end +function Sidebar:is_focused() + if not self:is_open() then return false end + + local current_winid = api.nvim_get_current_win() + if self.winids.result_container and self.winids.result_container == current_winid then return true end + if self.winids.selected_files_container and self.winids.selected_files_container == current_winid then + return true + end + if self.winids.selected_code_container and self.winids.selected_code_container == current_winid then return true end + if self.winids.input_container and self.winids.input_container == current_winid then return true end + + return false +end + function Sidebar:is_focused_on_result() return self:is_open() and self.result_container and self.result_container.winid == api.nvim_get_current_win() end