fix: open buffer (#2340)
This commit is contained in:
@@ -136,10 +136,11 @@ end
|
|||||||
function M.get_bufnr(abs_path)
|
function M.get_bufnr(abs_path)
|
||||||
local sidebar = require("avante").get()
|
local sidebar = require("avante").get()
|
||||||
if not sidebar then return 0, "Avante sidebar not found" end
|
if not sidebar then return 0, "Avante sidebar not found" end
|
||||||
local current_winid = vim.api.nvim_get_current_win()
|
local bufnr
|
||||||
vim.api.nvim_set_current_win(sidebar.code.winid)
|
vim.api.nvim_win_call(sidebar.code.winid, function()
|
||||||
local bufnr = Utils.open_buffer(abs_path)
|
vim.cmd("edit " .. abs_path)
|
||||||
vim.api.nvim_set_current_win(current_winid)
|
bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
end)
|
||||||
return bufnr, nil
|
return bufnr, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1021,10 +1021,18 @@ function M.open_buffer(path, set_current_buf)
|
|||||||
|
|
||||||
local abs_path = M.join_paths(M.get_project_root(), path)
|
local abs_path = M.join_paths(M.get_project_root(), path)
|
||||||
|
|
||||||
local bufnr = vim.fn.bufnr(abs_path, true)
|
local bufnr ---@type integer
|
||||||
|
if set_current_buf then
|
||||||
|
bufnr = vim.fn.bufnr(abs_path)
|
||||||
|
if bufnr ~= -1 and vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].modified then
|
||||||
|
vim.api.nvim_buf_call(bufnr, function() vim.cmd("noautocmd write") end)
|
||||||
|
end
|
||||||
|
vim.cmd("noautocmd edit " .. abs_path)
|
||||||
|
bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
else
|
||||||
|
bufnr = vim.fn.bufnr(abs_path, true)
|
||||||
pcall(vim.fn.bufload, bufnr)
|
pcall(vim.fn.bufload, bufnr)
|
||||||
|
end
|
||||||
if set_current_buf then vim.cmd("buffer " .. bufnr) end
|
|
||||||
|
|
||||||
vim.cmd("filetype detect")
|
vim.cmd("filetype detect")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user