fix: Ignore special buffers, fix auto-preview and not focus_on_open

This commit is contained in:
hedy
2023-11-30 10:17:00 +08:00
parent 4bbecbb92e
commit a5411b0a0c
3 changed files with 21 additions and 17 deletions

View File

@@ -184,26 +184,10 @@ function M.get_split_command()
end
end
---Whether table == {}
---@param t table
local function is_empty_table(t)
return t and next(t) == nil
end
local function table_has_content(t)
return t and next(t) ~= nil
end
local function has_value(tab, val)
for _, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
---Determine whether to include symbol in outline based on bufnr and its kind
---@param kind string
---@param bufnr integer

View File

@@ -191,6 +191,10 @@ function Preview:show()
return
end
if not vim.api.nvim_win_is_valid(self.s.code.win) then
return
end
if not self.buf or not self.win then
self:create()
else
@@ -289,6 +293,11 @@ function LivePreview:show()
return
end
if not vim.api.nvim_win_is_valid(self.s.code.win)
or (self.codewin and not vim.api.nvim_win_is_valid(self.codewin)) then
return
end
local node = self.s:_current_node()
if not node then
return

View File

@@ -105,6 +105,9 @@ function Sidebar:initial_handler(response, opts)
self.items = items
self:_update_lines(true)
if not cfg.o.outline_window.focus_on_open or not opts.focus_outline then
vim.fn.win_gotoid(self.code.win)
end
end
-- stylua: ignore start
@@ -325,10 +328,17 @@ end
---Re-request symbols from provider
function Sidebar:__refresh()
local focused_outline = self.view.buf == vim.api.nvim_get_current_buf()
local buf = vim.api.nvim_get_current_buf()
local focused_outline = self.view.buf == buf
if focused_outline or not self.view:is_open() then
return
end
local ft = vim.api.nvim_buf_get_option(buf, 'ft')
local nolisted = vim.api.nvim_buf_get_option(buf, 'buflisted')
local hidden = vim.api.nvim_buf_get_option(buf, 'bufhidden')
if ft == 'OutlineHelp' or nolisted or hidden then
return
end
self.provider = providers.find_provider()
if self.provider then
self.provider.request_symbols(function(res)
@@ -551,6 +561,7 @@ function Sidebar:open(opts)
self.provider.request_symbols(function(...)
self:initial_handler(...)
end, opts)
return
else
-- No provider
self:initial_setup(opts)