chore: add guards to prepare setup refactoring
This commit is contained in:
@@ -183,6 +183,8 @@ local function update_base_dir_with_filepath(filepath, bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.find_file(with_open)
|
function M.find_file(with_open)
|
||||||
|
if not with_open and not TreeExplorer then return end
|
||||||
|
|
||||||
local bufname = vim.fn.bufname()
|
local bufname = vim.fn.bufname()
|
||||||
local bufnr = api.nvim_get_current_buf()
|
local bufnr = api.nvim_get_current_buf()
|
||||||
local filepath = vim.fn.fnamemodify(bufname, ':p')
|
local filepath = vim.fn.fnamemodify(bufname, ':p')
|
||||||
@@ -224,6 +226,7 @@ function M.on_leave()
|
|||||||
end, 50)
|
end, 50)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: rewrite this to take into account setup by open
|
||||||
function M.open_on_directory()
|
function M.open_on_directory()
|
||||||
local should_proceed = _config.update_to_buf_dir.auto_open or view.win_open()
|
local should_proceed = _config.update_to_buf_dir.auto_open or view.win_open()
|
||||||
if not _config.update_to_buf_dir.enable or not should_proceed then
|
if not _config.update_to_buf_dir.enable or not should_proceed then
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ local M = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function M.fn(name)
|
function M.fn(name)
|
||||||
|
if not TreeExplorer then return end
|
||||||
|
|
||||||
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
|
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
|
||||||
local no_cwd_change = vim.fn.expand(foldername) == TreeExplorer.cwd
|
local no_cwd_change = vim.fn.expand(foldername) == TreeExplorer.cwd
|
||||||
local new_tab = a.nvim_get_current_tabpage()
|
local new_tab = a.nvim_get_current_tabpage()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ end
|
|||||||
|
|
||||||
local event_running = false
|
local event_running = false
|
||||||
function M.reload_explorer(callback)
|
function M.reload_explorer(callback)
|
||||||
if event_running or not TreeExplorer.cwd or vim.v.exiting ~= vim.NIL then
|
if event_running or not TreeExplorer or not TreeExplorer.cwd or vim.v.exiting ~= vim.NIL then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
event_running = true
|
event_running = true
|
||||||
@@ -52,7 +52,7 @@ function M.reload_explorer(callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.reload_git()
|
function M.reload_git()
|
||||||
if not git.config.enable or event_running then
|
if not TreeExplorer or not git.config.enable or event_running then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
event_running = true
|
event_running = true
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ local function get_node_at_line(line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.get_node_at_cursor()
|
function M.get_node_at_cursor()
|
||||||
|
if not TreeExplorer then return end
|
||||||
local winnr = view.get_winnr()
|
local winnr = view.get_winnr()
|
||||||
local hide_root_folder = view.View.hide_root_folder
|
local hide_root_folder = view.View.hide_root_folder
|
||||||
if not winnr then
|
if not winnr then
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ end
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.draw()
|
function M.draw()
|
||||||
if not TreeExplorer or not api.nvim_buf_is_loaded(view.View.bufnr) then
|
if not TreeExplorer or not view.View.bufnr or not api.nvim_buf_is_loaded(view.View.bufnr) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local cursor
|
local cursor
|
||||||
@@ -404,7 +404,7 @@ function M.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.render_hl(bufnr)
|
function M.render_hl(bufnr)
|
||||||
if not api.nvim_buf_is_loaded(bufnr) then return end
|
if not bufnr or not api.nvim_buf_is_loaded(bufnr) then return end
|
||||||
api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
|
api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
|
||||||
for _, data in ipairs(hl) do
|
for _, data in ipairs(hl) do
|
||||||
api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])
|
api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])
|
||||||
|
|||||||
Reference in New Issue
Block a user