fix: No-op keymaps when there is no provider
This commit is contained in:
@@ -191,7 +191,7 @@ function Preview:show()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not vim.api.nvim_win_is_valid(self.s.code.win) then
|
if not vim.api.nvim_win_is_valid(self.s.code.win) or not self.s.provider then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -296,6 +296,7 @@ function LivePreview:show()
|
|||||||
if
|
if
|
||||||
not vim.api.nvim_win_is_valid(self.s.code.win)
|
not vim.api.nvim_win_is_valid(self.s.code.win)
|
||||||
or (self.codewin and not vim.api.nvim_win_is_valid(self.codewin))
|
or (self.codewin and not vim.api.nvim_win_is_valid(self.codewin))
|
||||||
|
or not self.s.provider
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ function M.rename_symbol(sidebar)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local node = sidebar:_current_node()
|
local node = sidebar:_current_node()
|
||||||
|
if not node then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
-- Using fn.input so it's synchronous
|
-- Using fn.input so it's synchronous
|
||||||
local new_name = vim.fn.input({ prompt = 'New Name: ', default = node.name })
|
local new_name = vim.fn.input({ prompt = 'New Name: ', default = node.name })
|
||||||
@@ -140,6 +143,9 @@ function M.show_hover(sidebar)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local node = sidebar:_current_node()
|
local node = sidebar:_current_node()
|
||||||
|
if not node then
|
||||||
|
return false
|
||||||
|
end
|
||||||
local params = {
|
local params = {
|
||||||
textDocument = { uri = vim.uri_from_bufnr(sidebar.code.buf) },
|
textDocument = { uri = vim.uri_from_bufnr(sidebar.code.buf) },
|
||||||
position = { line = node.line, character = node.character },
|
position = { line = node.line, character = node.character },
|
||||||
|
|||||||
@@ -194,8 +194,10 @@ function Sidebar:setup_buffer_autocmd()
|
|||||||
vim.api.nvim_create_autocmd('CursorMoved', {
|
vim.api.nvim_create_autocmd('CursorMoved', {
|
||||||
buffer = 0,
|
buffer = 0,
|
||||||
callback = function()
|
callback = function()
|
||||||
|
if self.provider then
|
||||||
-- Don't use _goto_location because we don't want to auto-close
|
-- Don't use _goto_location because we don't want to auto-close
|
||||||
self:__goto_location(false)
|
self:__goto_location(false)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -363,15 +365,24 @@ function Sidebar:no_providers_ui()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Currently hovered node in outline
|
---Currently hovered node in outline
|
||||||
---@return outline.FlatSymbol
|
---@return outline.FlatSymbol?
|
||||||
function Sidebar:_current_node()
|
function Sidebar:_current_node()
|
||||||
local current_line = vim.api.nvim_win_get_cursor(self.view.win)[1]
|
local current_line = vim.api.nvim_win_get_cursor(self.view.win)[1]
|
||||||
|
if self.flats then
|
||||||
return self.flats[current_line]
|
return self.flats[current_line]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param change_focus boolean Whether to switch to code window after setting cursor
|
---@param change_focus boolean Whether to switch to code window after setting cursor
|
||||||
function Sidebar:__goto_location(change_focus)
|
function Sidebar:__goto_location(change_focus)
|
||||||
|
if not self.provider then
|
||||||
|
return
|
||||||
|
end
|
||||||
local node = self:_current_node()
|
local node = self:_current_node()
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
vim.api.nvim_win_set_cursor(self.code.win, { node.line + 1, node.character })
|
vim.api.nvim_win_set_cursor(self.code.win, { node.line + 1, node.character })
|
||||||
|
|
||||||
if cfg.o.outline_window.center_on_jump then
|
if cfg.o.outline_window.center_on_jump then
|
||||||
@@ -426,13 +437,18 @@ function Sidebar:_move_and_jump(direction)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param move_cursor boolean
|
---@param move_cursor boolean
|
||||||
---@param node_index integer Index for self.flats
|
function Sidebar:_toggle_fold(move_cursor)
|
||||||
function Sidebar:_toggle_fold(move_cursor, node_index)
|
if not self.provider then
|
||||||
local node = self.flats[node_index] or self:_current_node()
|
return
|
||||||
|
end
|
||||||
|
local node = self:_current_node()
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
local is_folded = folding.is_folded(node)
|
local is_folded = folding.is_folded(node)
|
||||||
|
|
||||||
if folding.is_foldable(node) then
|
if folding.is_foldable(node) then
|
||||||
self:_set_folded(not is_folded, move_cursor, node_index)
|
self:_set_folded(not is_folded, move_cursor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -440,6 +456,9 @@ end
|
|||||||
---@param move_cursor? boolean
|
---@param move_cursor? boolean
|
||||||
---@param node_index? integer
|
---@param node_index? integer
|
||||||
function Sidebar:_set_folded(folded, move_cursor, node_index)
|
function Sidebar:_set_folded(folded, move_cursor, node_index)
|
||||||
|
if not self.provider then
|
||||||
|
return
|
||||||
|
end
|
||||||
local node = self.flats[node_index] or self:_current_node()
|
local node = self.flats[node_index] or self:_current_node()
|
||||||
local changed = (folded ~= folding.is_folded(node))
|
local changed = (folded ~= folding.is_folded(node))
|
||||||
|
|
||||||
@@ -462,6 +481,9 @@ end
|
|||||||
|
|
||||||
---@param nodes outline.Symbol[]
|
---@param nodes outline.Symbol[]
|
||||||
function Sidebar:_toggle_all_fold(nodes)
|
function Sidebar:_toggle_all_fold(nodes)
|
||||||
|
if not self.provider then
|
||||||
|
return
|
||||||
|
end
|
||||||
nodes = nodes or self.items
|
nodes = nodes or self.items
|
||||||
local folded = true
|
local folded = true
|
||||||
|
|
||||||
@@ -478,8 +500,14 @@ end
|
|||||||
---@param folded boolean?
|
---@param folded boolean?
|
||||||
---@param nodes? outline.Symbol[]
|
---@param nodes? outline.Symbol[]
|
||||||
function Sidebar:_set_all_folded(folded, nodes)
|
function Sidebar:_set_all_folded(folded, nodes)
|
||||||
|
if not self.provider then
|
||||||
|
return
|
||||||
|
end
|
||||||
local stack = { nodes or self.items }
|
local stack = { nodes or self.items }
|
||||||
local current = self:_current_node()
|
local current = self:_current_node()
|
||||||
|
if not current then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
while #stack > 0 do
|
while #stack > 0 do
|
||||||
local current_nodes = table.remove(stack, #stack)
|
local current_nodes = table.remove(stack, #stack)
|
||||||
|
|||||||
Reference in New Issue
Block a user