fix: check if is sidebar buf (#179)
This commit is contained in:
parent
43c5544a29
commit
7bea73eb80
@ -1,5 +1,6 @@
|
||||
local api = vim.api
|
||||
|
||||
local Utils = require("avante.utils")
|
||||
local Sidebar = require("avante.sidebar")
|
||||
local Selection = require("avante.selection")
|
||||
local Config = require("avante.config")
|
||||
@ -168,10 +169,9 @@ M.refresh = function()
|
||||
return
|
||||
end
|
||||
|
||||
local ft = vim.api.nvim_get_option_value("filetype", { buf = curbuf })
|
||||
local listed = vim.api.nvim_get_option_value("buflisted", { buf = curbuf })
|
||||
|
||||
if ft == "Avante" or not listed then
|
||||
if Utils.is_sidebar_buffer(curbuf) or not listed then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
local Utils = require("avante.utils")
|
||||
local Config = require("avante.config")
|
||||
|
||||
local api = vim.api
|
||||
@ -66,7 +67,7 @@ function Selection:setup_autocmds()
|
||||
group = self.augroup,
|
||||
pattern = { "n:v", "n:V", "n:" }, -- Entering Visual mode from Normal mode
|
||||
callback = function(ev)
|
||||
if vim.bo[ev.buf].filetype ~= "Avante" then
|
||||
if not Utils.is_sidebar_buffer(ev.buf) then
|
||||
self:show_hints_popup()
|
||||
end
|
||||
end,
|
||||
@ -75,8 +76,8 @@ function Selection:setup_autocmds()
|
||||
api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
|
||||
group = self.augroup,
|
||||
callback = function(ev)
|
||||
if vim.bo[ev.buf].filetype ~= "Avante" then
|
||||
if vim.fn.mode() == "v" or vim.fn.mode() == "V" or vim.fn.mode() == "" then
|
||||
if not Utils.is_sidebar_buffer(ev.buf) then
|
||||
if Utils.in_visual_mode() then
|
||||
self:show_hints_popup()
|
||||
else
|
||||
self:close_hints_popup()
|
||||
@ -89,7 +90,7 @@ function Selection:setup_autocmds()
|
||||
group = self.augroup,
|
||||
pattern = { "v:n", "v:i", "v:c" }, -- Switching from visual mode back to normal, insert, or other modes
|
||||
callback = function(ev)
|
||||
if vim.bo[ev.buf].filetype ~= "Avante" then
|
||||
if not Utils.is_sidebar_buffer(ev.buf) then
|
||||
self:close_hints_popup()
|
||||
end
|
||||
end,
|
||||
|
@ -799,6 +799,12 @@ function Sidebar:on_mount()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
for _, comp in pairs(self) do
|
||||
if comp and type(comp) == "table" and comp.mount and comp.bufnr and api.nvim_buf_is_valid(comp.bufnr) then
|
||||
Utils.mark_as_sidebar_buffer(comp.bufnr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Sidebar:refresh_winids()
|
||||
|
@ -39,7 +39,7 @@ end
|
||||
|
||||
function M.in_visual_mode()
|
||||
local current_mode = vim.fn.mode()
|
||||
return current_mode == "v" or current_mode == "V" or current_mode == ""
|
||||
return current_mode == "v" or current_mode == "V" or current_mode == ""
|
||||
end
|
||||
|
||||
---Get the selected content and range in Visual mode
|
||||
@ -302,4 +302,18 @@ M.buf_list_wins = function(bufnr)
|
||||
return wins
|
||||
end
|
||||
|
||||
local sidebar_buffer_var_name = "is_avante_sidebar_buffer"
|
||||
|
||||
function M.mark_as_sidebar_buffer(bufnr)
|
||||
api.nvim_buf_set_var(bufnr, sidebar_buffer_var_name, true)
|
||||
end
|
||||
|
||||
function M.is_sidebar_buffer(bufnr)
|
||||
local ok, v = pcall(api.nvim_buf_get_var, bufnr, sidebar_buffer_var_name)
|
||||
if not ok then
|
||||
return false
|
||||
end
|
||||
return v == true
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
x
Reference in New Issue
Block a user