Compare commits
20 Commits
master
...
2826-remov
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec5d41f182 | ||
|
|
5737649ca9 | ||
|
|
fee19f491d | ||
|
|
0830436cca | ||
|
|
51b269dc71 | ||
|
|
82cc80ffa4 | ||
|
|
d84dfad1c3 | ||
|
|
4d6c42356a | ||
|
|
d72f85f524 | ||
|
|
e875f15b32 | ||
|
|
83fdff7c4a | ||
|
|
09ec00c085 | ||
|
|
3615c7dffe | ||
|
|
5fbd6745eb | ||
|
|
f1e9d5165c | ||
|
|
414e576bc2 | ||
|
|
de2ae0b06f | ||
|
|
d6cd465462 | ||
|
|
b7e9789850 | ||
|
|
6e7ce8771b |
@ -74,7 +74,7 @@ end
|
|||||||
|
|
||||||
function M.tab_enter()
|
function M.tab_enter()
|
||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
if explorer and explorer.view:is_visible({ any_tabpage = true }) then
|
if explorer and explorer.view:is_visible({ any_tabpage = true }, "nvim-tree.tab_enter") then
|
||||||
local bufname = vim.api.nvim_buf_get_name(0)
|
local bufname = vim.api.nvim_buf_get_name(0)
|
||||||
|
|
||||||
local ft
|
local ft
|
||||||
@ -97,7 +97,7 @@ end
|
|||||||
|
|
||||||
function M.open_on_directory()
|
function M.open_on_directory()
|
||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.view:is_visible()
|
local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.view:is_visible(nil, "nvim-tree.open_on_directory")
|
||||||
if not should_proceed then
|
if not should_proceed then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -669,7 +669,7 @@ function M.purge_all_state()
|
|||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
if explorer then
|
if explorer then
|
||||||
explorer.view:close_all_tabs()
|
explorer.view:close_all_tabs()
|
||||||
explorer.view:abandon_all_windows("purge_all_state")
|
explorer.view:abandon_all_windows()
|
||||||
require("nvim-tree.git").purge_state()
|
require("nvim-tree.git").purge_state()
|
||||||
explorer:destroy()
|
explorer:destroy()
|
||||||
core.reset_explorer()
|
core.reset_explorer()
|
||||||
|
|||||||
@ -13,7 +13,7 @@ local running = {}
|
|||||||
---@param path string relative or absolute
|
---@param path string relative or absolute
|
||||||
function M.fn(path)
|
function M.fn(path)
|
||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
if not explorer or not explorer.view:is_visible() then
|
if not explorer or not explorer.view:is_visible(nil, "finders/find-file.fn1") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ function M.fn(path)
|
|||||||
end)
|
end)
|
||||||
:iterate()
|
:iterate()
|
||||||
|
|
||||||
if found and explorer.view:is_visible() then
|
if found and explorer.view:is_visible(nil, "finders/find-file.fn2") then
|
||||||
explorer.renderer:draw()
|
explorer.renderer:draw()
|
||||||
explorer.view:set_cursor({ line, 0 })
|
explorer.view:set_cursor({ line, 0 })
|
||||||
end
|
end
|
||||||
|
|||||||
@ -18,7 +18,7 @@ local function close_windows(windows)
|
|||||||
-- Prevent from closing when the win count equals 1 or 2,
|
-- Prevent from closing when the win count equals 1 or 2,
|
||||||
-- where the win to remove could be the last opened.
|
-- where the win to remove could be the last opened.
|
||||||
-- For details see #2503.
|
-- For details see #2503.
|
||||||
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
|
if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,12 +36,12 @@ local function clear_buffer(absolute_path)
|
|||||||
for _, buf in pairs(bufs) do
|
for _, buf in pairs(bufs) do
|
||||||
if buf.name == absolute_path then
|
if buf.name == absolute_path then
|
||||||
local tree_winnr = vim.api.nvim_get_current_win()
|
local tree_winnr = vim.api.nvim_get_current_win()
|
||||||
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then
|
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.opts.view.float.enable) then
|
||||||
vim.api.nvim_set_current_win(buf.windows[1])
|
vim.api.nvim_set_current_win(buf.windows[1])
|
||||||
vim.cmd(":bn")
|
vim.cmd(":bn")
|
||||||
end
|
end
|
||||||
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
|
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
|
||||||
if explorer and not explorer.view.float.quit_on_focus_loss then
|
if explorer and not explorer.opts.view.float.quit_on_focus_loss then
|
||||||
vim.api.nvim_set_current_win(tree_winnr)
|
vim.api.nvim_set_current_win(tree_winnr)
|
||||||
end
|
end
|
||||||
if M.config.actions.remove_file.close_window then
|
if M.config.actions.remove_file.close_window then
|
||||||
|
|||||||
@ -23,7 +23,7 @@ local function usable_win_ids()
|
|||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||||
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||||
local tree_winid = explorer and explorer.view:get_winnr(tabpage, "open-file.usable_win_ids")
|
local tree_winid = explorer and explorer.view:get_winid(tabpage, "open-file.usable_win_ids")
|
||||||
|
|
||||||
return vim.tbl_filter(function(id)
|
return vim.tbl_filter(function(id)
|
||||||
local bufid = vim.api.nvim_win_get_buf(id)
|
local bufid = vim.api.nvim_win_get_buf(id)
|
||||||
@ -352,7 +352,7 @@ local function open_in_new_window(filename, mode)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.view.float.enable then
|
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.opts.view.float.enable then
|
||||||
-- ignore "WinLeave" autocmd on preview
|
-- ignore "WinLeave" autocmd on preview
|
||||||
-- because the registered "WinLeave"
|
-- because the registered "WinLeave"
|
||||||
-- will kill the floating window immediately
|
-- will kill the floating window immediately
|
||||||
|
|||||||
@ -41,7 +41,7 @@ function M.fn(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
if explorer and explorer.view:is_visible() then
|
if explorer and explorer.view:is_visible(nil, "tree/find-file.fn") then
|
||||||
-- focus
|
-- focus
|
||||||
if opts.focus then
|
if opts.focus then
|
||||||
lib.set_target_win()
|
lib.set_target_win()
|
||||||
|
|||||||
@ -25,7 +25,7 @@ function M.fn(opts)
|
|||||||
|
|
||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
|
|
||||||
if explorer and explorer.view:is_visible() then
|
if explorer and explorer.view:is_visible(nil, "open.fn") then
|
||||||
-- focus
|
-- focus
|
||||||
lib.set_target_win()
|
lib.set_target_win()
|
||||||
explorer.view:focus()
|
explorer.view:focus()
|
||||||
|
|||||||
@ -42,7 +42,7 @@ function M.fn(opts, no_focus, cwd, bang)
|
|||||||
opts.path = nil
|
opts.path = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if explorer and explorer.view:is_visible() then
|
if explorer and explorer.view:is_visible(nil, "toggle.fn") then
|
||||||
-- close
|
-- close
|
||||||
explorer.view:close(nil, "toggle.fn")
|
explorer.view:close(nil, "toggle.fn")
|
||||||
else
|
else
|
||||||
|
|||||||
@ -532,7 +532,7 @@ function Explorer:reload_explorer()
|
|||||||
|
|
||||||
local projects = git.reload_all_projects()
|
local projects = git.reload_all_projects()
|
||||||
self:refresh_nodes(projects)
|
self:refresh_nodes(projects)
|
||||||
if self.view:is_visible() then
|
if self.view:is_visible(nil, "Explorer:reload_explorer") then
|
||||||
self.renderer:draw()
|
self.renderer:draw()
|
||||||
end
|
end
|
||||||
event_running = false
|
event_running = false
|
||||||
@ -554,7 +554,7 @@ end
|
|||||||
---nil on no explorer or invalid view win
|
---nil on no explorer or invalid view win
|
||||||
---@return integer[]|nil
|
---@return integer[]|nil
|
||||||
function Explorer:get_cursor_position()
|
function Explorer:get_cursor_position()
|
||||||
local winnr = self.view:get_winnr(nil, "Explorer:get_cursor_position")
|
local winnr = self.view:get_winid(nil, "Explorer:get_cursor_position")
|
||||||
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
|
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@ -61,7 +61,7 @@ local overlay_bufnr = 0
|
|||||||
local overlay_winnr = 0
|
local overlay_winnr = 0
|
||||||
|
|
||||||
local function remove_overlay(self)
|
local function remove_overlay(self)
|
||||||
if self.explorer.view.float.enable and self.explorer.view.float.quit_on_focus_loss then
|
if self.explorer.opts.view.float.enable and self.explorer.opts.view.float.quit_on_focus_loss then
|
||||||
-- return to normal nvim-tree float behaviour when filter window is closed
|
-- return to normal nvim-tree float behaviour when filter window is closed
|
||||||
vim.api.nvim_create_autocmd("WinLeave", {
|
vim.api.nvim_create_autocmd("WinLeave", {
|
||||||
pattern = "NvimTree_*",
|
pattern = "NvimTree_*",
|
||||||
@ -171,7 +171,7 @@ local function calculate_overlay_win_width(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function create_overlay(self)
|
local function create_overlay(self)
|
||||||
if self.explorer.view.float.enable then
|
if self.explorer.opts.view.float.enable then
|
||||||
-- don't close nvim-tree float when focus is changed to filter window
|
-- don't close nvim-tree float when focus is changed to filter window
|
||||||
vim.api.nvim_clear_autocmds({
|
vim.api.nvim_clear_autocmds({
|
||||||
event = "WinLeave",
|
event = "WinLeave",
|
||||||
|
|||||||
@ -7,31 +7,21 @@ local globals = require("nvim-tree.globals")
|
|||||||
|
|
||||||
local Class = require("nvim-tree.classic")
|
local Class = require("nvim-tree.classic")
|
||||||
|
|
||||||
---@class OpenInWinOpts
|
---Window and buffer related settings and operations
|
||||||
---@field hijack_current_buf boolean|nil default true
|
|
||||||
---@field resize boolean|nil default true
|
|
||||||
---@field winid number|nil 0 or nil for current
|
|
||||||
|
|
||||||
local DEFAULT_MIN_WIDTH = 30
|
|
||||||
local DEFAULT_MAX_WIDTH = -1
|
|
||||||
local DEFAULT_PADDING = 1
|
|
||||||
|
|
||||||
---@class (exact) View: Class
|
---@class (exact) View: Class
|
||||||
---@field live_filter table
|
---@field live_filter table
|
||||||
---@field side string
|
---@field side string
|
||||||
---@field float table
|
|
||||||
---@field private explorer Explorer
|
---@field private explorer Explorer
|
||||||
---@field private adaptive_size boolean
|
---@field private adaptive_size boolean
|
||||||
---@field private centralize_selection boolean
|
|
||||||
---@field private hide_root_folder boolean
|
|
||||||
---@field private winopts table
|
---@field private winopts table
|
||||||
---@field private height integer
|
|
||||||
---@field private preserve_window_proportions boolean
|
|
||||||
---@field private initial_width integer
|
---@field private initial_width integer
|
||||||
---@field private width (fun():integer)|integer|string
|
---@field private width (fun():integer)|integer|string
|
||||||
---@field private max_width integer
|
---@field private max_width integer
|
||||||
---@field private padding integer
|
---@field private padding integer
|
||||||
---@field private bufnr_by_tab table<integer, integer> stored per tab until multi-instance is complete
|
-- TODO multi-instance remove or replace with single member
|
||||||
|
---@field private bufnr_by_tabid table<integer, integer>
|
||||||
|
-- TODO multi-instance change to single member
|
||||||
|
---@field private cursors_by_tabid table<integer, integer[]> as per vim.api.nvim_win_get_cursor
|
||||||
local View = Class:extend()
|
local View = Class:extend()
|
||||||
|
|
||||||
---@class View
|
---@class View
|
||||||
@ -45,18 +35,14 @@ local View = Class:extend()
|
|||||||
function View:new(args)
|
function View:new(args)
|
||||||
args.explorer:log_new("View")
|
args.explorer:log_new("View")
|
||||||
|
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
self.adaptive_size = false
|
self.adaptive_size = false
|
||||||
self.centralize_selection = self.explorer.opts.view.centralize_selection
|
self.side = (self.explorer.opts.view.side == "right") and "right" or "left"
|
||||||
self.float = self.explorer.opts.view.float
|
self.live_filter = { prev_focused_node = nil, }
|
||||||
self.height = self.explorer.opts.view.height
|
self.bufnr_by_tabid = {}
|
||||||
self.hide_root_folder = self.explorer.opts.renderer.root_folder_label == false
|
self.cursors_by_tabid = {}
|
||||||
self.preserve_window_proportions = self.explorer.opts.view.preserve_window_proportions
|
|
||||||
self.side = (self.explorer.opts.view.side == "right") and "right" or "left"
|
|
||||||
self.live_filter = { prev_focused_node = nil, }
|
|
||||||
self.bufnr_by_tab = {}
|
|
||||||
|
|
||||||
self.winopts = {
|
self.winopts = {
|
||||||
relativenumber = self.explorer.opts.view.relativenumber,
|
relativenumber = self.explorer.opts.view.relativenumber,
|
||||||
number = self.explorer.opts.view.number,
|
number = self.explorer.opts.view.number,
|
||||||
list = false,
|
list = false,
|
||||||
@ -77,20 +63,16 @@ function View:new(args)
|
|||||||
|
|
||||||
self:configure_width(self.explorer.opts.view.width)
|
self:configure_width(self.explorer.opts.view.width)
|
||||||
self.initial_width = self:get_width()
|
self.initial_width = self:get_width()
|
||||||
|
|
||||||
|
-- TODO multi-instance remove this; delete buffers rather than retaining them
|
||||||
|
local tabid = vim.api.nvim_get_current_tabpage()
|
||||||
|
self.bufnr_by_tabid[tabid] = globals.BUFNR_BY_TABID[tabid]
|
||||||
end
|
end
|
||||||
|
|
||||||
function View:destroy()
|
function View:destroy()
|
||||||
self.explorer:log_destroy("View")
|
self.explorer:log_destroy("View")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- The initial state of a tab
|
|
||||||
local tabinitial = {
|
|
||||||
-- The position of the cursor { line, column }
|
|
||||||
cursor = { 0, 0 },
|
|
||||||
-- The NvimTree window number
|
|
||||||
winnr = nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
---@type { name: string, value: any }[]
|
---@type { name: string, value: any }[]
|
||||||
local BUFFER_OPTIONS = {
|
local BUFFER_OPTIONS = {
|
||||||
{ name = "bufhidden", value = "wipe" },
|
{ name = "bufhidden", value = "wipe" },
|
||||||
@ -101,11 +83,12 @@ local BUFFER_OPTIONS = {
|
|||||||
{ name = "swapfile", value = false },
|
{ name = "swapfile", value = false },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- TODO multi-instance remove this; delete buffers rather than retaining them
|
||||||
---@private
|
---@private
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function View:matches_bufnr(bufnr)
|
function View:matches_bufnr(bufnr)
|
||||||
for _, b in pairs(globals.BUFNR_PER_TAB) do
|
for _, b in pairs(globals.BUFNR_BY_TABID) do
|
||||||
if b == bufnr then
|
if b == bufnr then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -113,6 +96,7 @@ function View:matches_bufnr(bufnr)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO multi-instance remove this; delete buffers rather than retaining them
|
||||||
---@private
|
---@private
|
||||||
function View:wipe_rogue_buffer()
|
function View:wipe_rogue_buffer()
|
||||||
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
@ -127,23 +111,23 @@ end
|
|||||||
function View:create_buffer(bufnr)
|
function View:create_buffer(bufnr)
|
||||||
self:wipe_rogue_buffer()
|
self:wipe_rogue_buffer()
|
||||||
|
|
||||||
local tab = vim.api.nvim_get_current_tabpage()
|
local tabid = vim.api.nvim_get_current_tabpage()
|
||||||
globals.BUFNR_PER_TAB[tab] = bufnr or vim.api.nvim_create_buf(false, false)
|
|
||||||
|
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
bufnr = bufnr or vim.api.nvim_create_buf(false, false)
|
||||||
self.bufnr_by_tab[tab] = globals.BUFNR_PER_TAB[tab]
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.api.nvim_buf_set_name(self:get_bufnr("View:create_buffer1"), "NvimTree_" .. tab)
|
-- set both bufnr registries
|
||||||
|
globals.BUFNR_BY_TABID[tabid] = bufnr
|
||||||
|
self.bufnr_by_tabid[tabid] = bufnr
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, "NvimTree_" .. tabid)
|
||||||
|
|
||||||
bufnr = self:get_bufnr("View:create_buffer2")
|
|
||||||
for _, option in ipairs(BUFFER_OPTIONS) do
|
for _, option in ipairs(BUFFER_OPTIONS) do
|
||||||
vim.api.nvim_set_option_value(option.name, option.value, { buf = bufnr })
|
vim.api.nvim_set_option_value(option.name, option.value, { buf = bufnr })
|
||||||
end
|
end
|
||||||
|
|
||||||
require("nvim-tree.keymap").on_attach(self:get_bufnr("View:create_buffer3"))
|
require("nvim-tree.keymap").on_attach(bufnr)
|
||||||
|
|
||||||
events._dispatch_tree_attached_post(self:get_bufnr("View:create_buffer4"))
|
events._dispatch_tree_attached_post(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
@ -175,24 +159,6 @@ local move_tbl = {
|
|||||||
right = "L",
|
right = "L",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- setup_tabpage sets up the initial state of a tab
|
|
||||||
---@private
|
|
||||||
---@param tabpage integer
|
|
||||||
---@param callsite string
|
|
||||||
function View:setup_tabpage(tabpage, callsite)
|
|
||||||
local winnr = vim.api.nvim_get_current_win()
|
|
||||||
|
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
|
||||||
log.line("dev", "View:setup_tabpage(%3s, %-20.20s) w%d %s",
|
|
||||||
tabpage,
|
|
||||||
callsite,
|
|
||||||
winnr,
|
|
||||||
globals.TABPAGES[tabpage] and vim.inspect(globals.TABPAGES[tabpage], { newline = "" }) or "tabinitial")
|
|
||||||
end
|
|
||||||
|
|
||||||
globals.TABPAGES[tabpage] = vim.tbl_extend("force", globals.TABPAGES[tabpage] or tabinitial, { winnr = winnr })
|
|
||||||
end
|
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function View:set_window_options_and_buffer()
|
function View:set_window_options_and_buffer()
|
||||||
pcall(vim.api.nvim_command, "buffer " .. self:get_bufnr("View:set_window_options_and_buffer"))
|
pcall(vim.api.nvim_command, "buffer " .. self:get_bufnr("View:set_window_options_and_buffer"))
|
||||||
@ -223,22 +189,22 @@ end
|
|||||||
---@private
|
---@private
|
||||||
---@return table
|
---@return table
|
||||||
function View:open_win_config()
|
function View:open_win_config()
|
||||||
if type(self.float.open_win_config) == "function" then
|
if type(self.explorer.opts.view.float.open_win_config) == "function" then
|
||||||
return self.float.open_win_config()
|
return self.explorer.opts.view.float.open_win_config()
|
||||||
else
|
else
|
||||||
return self.float.open_win_config
|
return self.explorer.opts.view.float.open_win_config
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function View:open_window()
|
function View:open_window()
|
||||||
if self.float.enable then
|
if self.explorer.opts.view.float.enable then
|
||||||
vim.api.nvim_open_win(0, true, self:open_win_config())
|
vim.api.nvim_open_win(0, true, self:open_win_config())
|
||||||
else
|
else
|
||||||
vim.api.nvim_command("vsp")
|
vim.api.nvim_command("vsp")
|
||||||
self:reposition_window()
|
self:reposition_window()
|
||||||
end
|
end
|
||||||
self:setup_tabpage(vim.api.nvim_get_current_tabpage(), "View:open_window")
|
globals.WINID_BY_TABID[vim.api.nvim_get_current_tabpage()] = vim.api.nvim_get_current_win()
|
||||||
self:set_window_options_and_buffer()
|
self:set_window_options_and_buffer()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -273,37 +239,43 @@ local function switch_buf_if_last_buf()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---save_tab_state saves any state that should be preserved across redraws.
|
---save any state that should be preserved on reopening
|
||||||
---@private
|
---@private
|
||||||
---@param tabnr integer
|
---@param tabid integer
|
||||||
function View:save_tab_state(tabnr)
|
function View:save_state(tabid)
|
||||||
local tabpage = tabnr or vim.api.nvim_get_current_tabpage()
|
tabid = tabid or vim.api.nvim_get_current_tabpage()
|
||||||
globals.CURSORS[tabpage] = vim.api.nvim_win_get_cursor(self:get_winnr(tabpage, "View:save_tab_state") or 0)
|
self.cursors_by_tabid[tabid] = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
---@param tabpage integer
|
---@param tabid integer
|
||||||
function View:close_internal(tabpage)
|
function View:close_internal(tabid)
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
log.line("dev", "View:close_internal(t%s)", tabpage)
|
log.line("dev", "View:close_internal(t%s)", tabid)
|
||||||
end
|
end
|
||||||
if not self:is_visible({ tabpage = tabpage }) then
|
--- END multi-instance FF
|
||||||
|
|
||||||
|
if not self:is_visible({ tabpage = tabid }, "View:close_internal") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self:save_tab_state(tabpage)
|
self:save_state(tabid)
|
||||||
switch_buf_if_last_buf()
|
switch_buf_if_last_buf()
|
||||||
local tree_win = self:get_winnr(tabpage, "View:close_internal")
|
local tree_win = self:get_winid(tabid, "View:close_internal")
|
||||||
local current_win = vim.api.nvim_get_current_win()
|
local current_win = vim.api.nvim_get_current_win()
|
||||||
for _, win in pairs(vim.api.nvim_tabpage_list_wins(tabpage)) do
|
for _, win in pairs(vim.api.nvim_tabpage_list_wins(tabid)) do
|
||||||
if vim.api.nvim_win_get_config(win).relative == "" then
|
if vim.api.nvim_win_get_config(win).relative == "" then
|
||||||
local prev_win = vim.fn.winnr("#") -- this tab only
|
local prev_win = vim.fn.winnr("#") -- this tab only
|
||||||
if tree_win == current_win and prev_win > 0 then
|
if tree_win == current_win and prev_win > 0 then
|
||||||
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
|
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
|
||||||
end
|
end
|
||||||
if vim.api.nvim_win_is_valid(tree_win or 0) then
|
if vim.api.nvim_win_is_valid(tree_win or 0) then
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
log.line("dev", "View:close_internal(t%s) w%s", tabpage, tree_win)
|
log.line("dev", "View:close_internal(t%s) w%s", tabid, tree_win)
|
||||||
end
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
---
|
||||||
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
|
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
|
||||||
if not success then
|
if not success then
|
||||||
notify.debug("Failed to close window: " .. error)
|
notify.debug("Failed to close window: " .. error)
|
||||||
@ -316,26 +288,42 @@ function View:close_internal(tabpage)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function View:close_this_tab_only()
|
function View:close_this_tab_only()
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
|
log.line("dev", "View:close_this_tab_only()")
|
||||||
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
|
||||||
self:close_internal(vim.api.nvim_get_current_tabpage())
|
self:close_internal(vim.api.nvim_get_current_tabpage())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO this is broken at 1.13.0 - current tab does not close when tab.sync.close is set
|
||||||
function View:close_all_tabs()
|
function View:close_all_tabs()
|
||||||
for tabpage, _ in pairs(globals.TABPAGES) do
|
log.line("dev", "View:close_all_tabs() globals.WINID_BY_TABID=%s", vim.inspect(globals.WINID_BY_TABID))
|
||||||
self:close_internal(tabpage)
|
for tabid, _ in pairs(globals.WINID_BY_TABID) do
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
|
log.line("dev", "View:close_all_tabs()")
|
||||||
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
|
||||||
|
self:close_internal(tabid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param tabpage integer|nil
|
---@param tabid integer|nil
|
||||||
---@param callsite string
|
---@param callsite string
|
||||||
function View:close(tabpage, callsite)
|
function View:close(tabid, callsite)
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
log.line("dev", "View:close(t%s, %s)", tabpage, callsite)
|
log.line("dev", "View:close(t%s, %s)", tabid, callsite)
|
||||||
end
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
|
||||||
if self.explorer.opts.tab.sync.close then
|
if self.explorer.opts.tab.sync.close then
|
||||||
self:close_all_tabs()
|
self:close_all_tabs()
|
||||||
elseif tabpage then
|
elseif tabid then
|
||||||
self:close_internal(tabpage)
|
self:close_internal(tabid)
|
||||||
else
|
else
|
||||||
self:close_this_tab_only()
|
self:close_this_tab_only()
|
||||||
end
|
end
|
||||||
@ -343,7 +331,7 @@ end
|
|||||||
|
|
||||||
---@param options table|nil
|
---@param options table|nil
|
||||||
function View:open(options)
|
function View:open(options)
|
||||||
if self:is_visible() then
|
if self:is_visible(nil, "View:open") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -371,7 +359,7 @@ function View:grow()
|
|||||||
local padding = self:get_size(self.padding)
|
local padding = self:get_size(self.padding)
|
||||||
|
|
||||||
-- account for sign/number columns etc.
|
-- account for sign/number columns etc.
|
||||||
local wininfo = vim.fn.getwininfo(self:get_winnr(nil, "View:grow"))
|
local wininfo = vim.fn.getwininfo(self:get_winid(nil, "View:grow"))
|
||||||
if type(wininfo) == "table" and type(wininfo[1]) == "table" then
|
if type(wininfo) == "table" and type(wininfo[1]) == "table" then
|
||||||
padding = padding + wininfo[1].textoff
|
padding = padding + wininfo[1].textoff
|
||||||
end
|
end
|
||||||
@ -411,9 +399,9 @@ end
|
|||||||
|
|
||||||
---@param size string|number|nil
|
---@param size string|number|nil
|
||||||
function View:resize(size)
|
function View:resize(size)
|
||||||
if self.float.enable and not self.adaptive_size then
|
if self.explorer.opts.view.float.enable and not self.adaptive_size then
|
||||||
-- if the floating windows's adaptive size is not desired, then the
|
-- if the floating windows's adaptive size is not desired, then the
|
||||||
-- float size should be defined in view.float.open_win_config
|
-- float size should be defined in self.explorer.opts.view.float.open_win_config
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -433,20 +421,19 @@ function View:resize(size)
|
|||||||
|
|
||||||
if size then
|
if size then
|
||||||
self.width = size
|
self.width = size
|
||||||
self.height = size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not self:is_visible() then
|
if not self:is_visible(nil, "View:resize") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local winnr = self:get_winnr(nil, "View:resize") or 0
|
local winid = self:get_winid(nil, "View:resize") or 0
|
||||||
|
|
||||||
local new_size = self:get_width()
|
local new_size = self:get_width()
|
||||||
|
|
||||||
if new_size ~= vim.api.nvim_win_get_width(winnr) then
|
if new_size ~= vim.api.nvim_win_get_width(winid) then
|
||||||
vim.api.nvim_win_set_width(winnr, new_size)
|
vim.api.nvim_win_set_width(winid, new_size)
|
||||||
if not self.preserve_window_proportions then
|
if not self.explorer.opts.view.preserve_window_proportions then
|
||||||
vim.cmd(":wincmd =")
|
vim.cmd(":wincmd =")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -462,24 +449,16 @@ function View:reposition_window()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
---@param callsite string
|
function View:set_current_win()
|
||||||
function View:set_current_win(callsite)
|
|
||||||
local current_tab = vim.api.nvim_get_current_tabpage()
|
local current_tab = vim.api.nvim_get_current_tabpage()
|
||||||
local current_win = vim.api.nvim_get_current_win()
|
globals.WINID_BY_TABID[current_tab] = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
|
||||||
log.line("dev", "View:set_current_win(%-20.20s) t%d w%3s->w%3s %s",
|
|
||||||
callsite,
|
|
||||||
current_tab,
|
|
||||||
globals.TABPAGES[current_tab].winnr,
|
|
||||||
current_win,
|
|
||||||
(globals.TABPAGES[current_tab].winnr == current_win) and "" or "MISMATCH"
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
globals.TABPAGES[current_tab].winnr = current_win
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class OpenInWinOpts
|
||||||
|
---@field hijack_current_buf boolean|nil default true
|
||||||
|
---@field resize boolean|nil default true
|
||||||
|
---@field winid number|nil 0 or nil for current
|
||||||
|
|
||||||
---Open the tree in the a window
|
---Open the tree in the a window
|
||||||
---@param opts OpenInWinOpts|nil
|
---@param opts OpenInWinOpts|nil
|
||||||
function View:open_in_win(opts)
|
function View:open_in_win(opts)
|
||||||
@ -489,8 +468,8 @@ function View:open_in_win(opts)
|
|||||||
vim.api.nvim_set_current_win(opts.winid)
|
vim.api.nvim_set_current_win(opts.winid)
|
||||||
end
|
end
|
||||||
self:create_buffer(opts.hijack_current_buf and vim.api.nvim_get_current_buf())
|
self:create_buffer(opts.hijack_current_buf and vim.api.nvim_get_current_buf())
|
||||||
self:setup_tabpage(vim.api.nvim_get_current_tabpage(), "View:open_in_win")
|
globals.WINID_BY_TABID[vim.api.nvim_get_current_tabpage()] = vim.api.nvim_get_current_win()
|
||||||
self:set_current_win("View:open_in_win")
|
self:set_current_win()
|
||||||
self:set_window_options_and_buffer()
|
self:set_window_options_and_buffer()
|
||||||
if opts.resize then
|
if opts.resize then
|
||||||
self:reposition_window()
|
self:reposition_window()
|
||||||
@ -502,180 +481,207 @@ end
|
|||||||
function View:abandon_current_window()
|
function View:abandon_current_window()
|
||||||
local tab = vim.api.nvim_get_current_tabpage()
|
local tab = vim.api.nvim_get_current_tabpage()
|
||||||
|
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
log.line("dev", "View:abandon_current_window() t%d w%s b%s member b%s %s",
|
log.line("dev", "View:abandon_current_window() t%d w%s b%s member b%s %s",
|
||||||
tab,
|
tab,
|
||||||
globals.TABPAGES[tab] and globals.TABPAGES[tab].winnr or nil,
|
globals.WINID_BY_TABID[tab],
|
||||||
globals.BUFNR_PER_TAB[tab],
|
globals.BUFNR_BY_TABID[tab],
|
||||||
self.bufnr_by_tab[tab],
|
self.bufnr_by_tabid[tab],
|
||||||
(globals.BUFNR_PER_TAB[tab] == self.bufnr_by_tab[tab]) and "" or "MISMATCH")
|
(globals.BUFNR_BY_TABID[tab] == self.bufnr_by_tabid[tab]) and "" or "MISMATCH")
|
||||||
|
|
||||||
self.bufnr_by_tab[tab] = nil
|
|
||||||
end
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
|
||||||
-- TODO multi-instance kill the buffer instead of retaining
|
-- reset both bufnr registries
|
||||||
|
globals.BUFNR_BY_TABID[tab] = nil
|
||||||
|
self.bufnr_by_tabid[tab] = nil
|
||||||
|
|
||||||
globals.BUFNR_PER_TAB[tab] = nil
|
globals.WINID_BY_TABID[tab] = nil
|
||||||
if globals.TABPAGES[tab] then
|
|
||||||
globals.TABPAGES[tab].winnr = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param callsite string
|
function View:abandon_all_windows()
|
||||||
function View:abandon_all_windows(callsite)
|
|
||||||
for tab, _ in pairs(vim.api.nvim_list_tabpages()) do
|
for tab, _ in pairs(vim.api.nvim_list_tabpages()) do
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
globals.BUFNR_BY_TABID[tab] = nil
|
||||||
log.line("dev", "View:abandon_all_windows(%-20.20s) t%d w%s b%s member b%s %s",
|
globals.WINID_BY_TABID[tab] = nil
|
||||||
callsite,
|
|
||||||
tab,
|
|
||||||
globals.TABPAGES and globals.TABPAGES.winnr or nil,
|
|
||||||
globals.BUFNR_PER_TAB[tab],
|
|
||||||
self.bufnr_by_tab[tab],
|
|
||||||
(globals.BUFNR_PER_TAB[tab] == self.bufnr_by_tab[tab]) and "" or "MISMATCH")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TODO multi-instance kill the buffer instead of retaining
|
|
||||||
|
|
||||||
globals.BUFNR_PER_TAB[tab] = nil
|
|
||||||
if globals.TABPAGES[tab] then
|
|
||||||
globals.TABPAGES[tab].winnr = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param opts table|nil
|
---@param opts table|nil
|
||||||
|
---@param callsite string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function View:is_visible(opts)
|
function View:is_visible(opts, callsite)
|
||||||
|
local msg
|
||||||
|
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
|
msg = string.format("View:is_visible(%s, %-20.20s)", vim.inspect(opts, { newline = "" }), callsite)
|
||||||
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
|
||||||
if opts and opts.tabpage then
|
if opts and opts.tabpage then
|
||||||
if globals.TABPAGES[opts.tabpage] == nil then
|
--- BEGIN multi-instance FF
|
||||||
return false
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
|
local winid = self:winid(opts.tabpage)
|
||||||
|
local winid_by_tabid = opts.tabpage and globals.WINID_BY_TABID[opts.tabpage] or nil
|
||||||
|
msg = string.format("%s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s",
|
||||||
|
msg,
|
||||||
|
opts.tabpage, winid_by_tabid,
|
||||||
|
opts.tabpage, winid
|
||||||
|
)
|
||||||
|
if winid ~= winid_by_tabid then
|
||||||
|
msg = string.format("%s MISMATCH", msg)
|
||||||
|
notify.error(msg)
|
||||||
|
end
|
||||||
|
log.line("dev", "%s", msg)
|
||||||
|
|
||||||
|
return winid and vim.api.nvim_win_is_valid(winid) or false
|
||||||
|
--- END multi-instance FF
|
||||||
|
else
|
||||||
|
local winid = globals.WINID_BY_TABID[opts.tabpage]
|
||||||
|
return winid and vim.api.nvim_win_is_valid(winid)
|
||||||
end
|
end
|
||||||
local winnr = globals.TABPAGES[opts.tabpage].winnr
|
|
||||||
return winnr and vim.api.nvim_win_is_valid(winnr)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts and opts.any_tabpage then
|
if opts and opts.any_tabpage then
|
||||||
for _, v in pairs(globals.TABPAGES) do
|
for tabid, winid_by_tabid in pairs(globals.WINID_BY_TABID) do
|
||||||
if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then
|
--- BEGIN multi-instance FF
|
||||||
return true
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
|
local winid = self:winid(tabid)
|
||||||
|
msg = string.format("%s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s",
|
||||||
|
msg,
|
||||||
|
tabid, winid_by_tabid,
|
||||||
|
tabid, winid
|
||||||
|
)
|
||||||
|
if winid ~= winid_by_tabid then
|
||||||
|
msg = string.format("%s MISMATCH", msg)
|
||||||
|
notify.error(msg)
|
||||||
|
end
|
||||||
|
log.line("dev", "%s", msg)
|
||||||
|
|
||||||
|
if winid and vim.api.nvim_win_is_valid(winid) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
else
|
||||||
|
if winid_by_tabid and vim.api.nvim_win_is_valid(winid_by_tabid) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return self:get_winnr(nil, "View:is_visible1") ~= nil and vim.api.nvim_win_is_valid(self:get_winnr(nil, "View:is_visible2") or 0)
|
local winid = self:get_winid(nil, "View:is_visible")
|
||||||
|
return winid ~= nil and vim.api.nvim_win_is_valid(winid or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param opts table|nil
|
---@param opts table|nil
|
||||||
function View:set_cursor(opts)
|
function View:set_cursor(opts)
|
||||||
if self:is_visible() then
|
if self:is_visible(nil, "View:set_cursor") then
|
||||||
pcall(vim.api.nvim_win_set_cursor, self:get_winnr(nil, "View:set_cursor"), opts)
|
pcall(vim.api.nvim_win_set_cursor, self:get_winid(nil, "View:set_cursor"), opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param winnr number|nil
|
---@param winid number|nil
|
||||||
---@param open_if_closed boolean|nil
|
---@param open_if_closed boolean|nil
|
||||||
function View:focus(winnr, open_if_closed)
|
function View:focus(winid, open_if_closed)
|
||||||
local wnr = winnr or self:get_winnr(nil, "View:focus1")
|
local wid = winid or self:get_winid(nil, "View:focus1")
|
||||||
|
|
||||||
if vim.api.nvim_win_get_tabpage(wnr or 0) ~= vim.api.nvim_win_get_tabpage(0) then
|
if vim.api.nvim_win_get_tabpage(wid or 0) ~= vim.api.nvim_win_get_tabpage(0) then
|
||||||
self:close(nil, "View:focus")
|
self:close(nil, "View:focus")
|
||||||
self:open()
|
self:open()
|
||||||
wnr = self:get_winnr(nil, "View:focus2")
|
wid = self:get_winid(nil, "View:focus2")
|
||||||
elseif open_if_closed and not self:is_visible() then
|
elseif open_if_closed and not self:is_visible(nil, "View:focus") then
|
||||||
self:open()
|
self:open()
|
||||||
end
|
end
|
||||||
|
|
||||||
if wnr then
|
if wid then
|
||||||
vim.api.nvim_set_current_win(wnr)
|
vim.api.nvim_set_current_win(wid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Retrieve the winid of the open tree.
|
--- Retrieve the winid of the open tree.
|
||||||
---@param opts ApiTreeWinIdOpts|nil
|
---@param opts ApiTreeWinIdOpts|nil
|
||||||
---@return number|nil winid unlike get_winnr(), this returns nil if the nvim-tree window is not visible
|
---@return number|nil winid unlike get_winid(), this returns nil if the nvim-tree window is not visible
|
||||||
function View:api_winid(opts)
|
function View:api_winid(opts)
|
||||||
local tabpage = opts and opts.tabpage
|
local tabpage = opts and opts.tabpage
|
||||||
if tabpage == 0 then
|
if tabpage == 0 then
|
||||||
tabpage = vim.api.nvim_get_current_tabpage()
|
tabpage = vim.api.nvim_get_current_tabpage()
|
||||||
end
|
end
|
||||||
if self:is_visible({ tabpage = tabpage }) then
|
if self:is_visible({ tabpage = tabpage }, "View:api_winid") then
|
||||||
return self:get_winnr(tabpage, "View:winid")
|
return self:get_winid(tabpage, "View:winid")
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Restores the state of a NvimTree window if it was initialized before.
|
---restore any state from last close
|
||||||
function View:restore_tab_state()
|
function View:restore_state()
|
||||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
self:set_cursor(self.cursors_by_tabid[vim.api.nvim_get_current_tabpage()])
|
||||||
self:set_cursor(globals.CURSORS[tabpage])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- winid containing the buffer
|
--- winid containing the buffer
|
||||||
---@param tabpage number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
---@param tabid number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
||||||
---@param callsite string
|
|
||||||
---@return integer? winid
|
---@return integer? winid
|
||||||
function View:winid(tabpage, callsite)
|
function View:winid(tabid)
|
||||||
local bufnr = self.bufnr_by_tab[tabpage]
|
local bufnr = self.bufnr_by_tabid[tabid]
|
||||||
|
|
||||||
local msg = string.format("View:winid(%3s, %-20.20s)", tabpage, callsite)
|
|
||||||
|
|
||||||
if bufnr then
|
if bufnr then
|
||||||
for _, w in pairs(vim.api.nvim_tabpage_list_wins(tabpage or 0)) do
|
for _, winid in pairs(vim.api.nvim_tabpage_list_wins(tabid or 0)) do
|
||||||
if vim.api.nvim_win_get_buf(w) == bufnr then
|
if vim.api.nvim_win_get_buf(winid) == bufnr then
|
||||||
log.line("dev", "%s b%d : w%s", msg, bufnr, w)
|
return winid
|
||||||
return w
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
log.line("dev", "%s no bufnr", msg)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Returns the window number for nvim-tree within the tabpage specified
|
--- Returns the window number for nvim-tree within the tabpage specified
|
||||||
---@param tabpage number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
---@param tabid number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
||||||
---@param callsite string
|
---@param callsite string
|
||||||
---@return number|nil
|
---@return number|nil
|
||||||
function View:get_winnr(tabpage, callsite)
|
function View:get_winid(tabid, callsite)
|
||||||
|
local tabid_param = tabid
|
||||||
|
tabid = tabid or vim.api.nvim_get_current_tabpage()
|
||||||
|
local global_winid = nil
|
||||||
|
|
||||||
|
--- BEGIN multi-instance FF
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
local msg = string.format("View:get_winnr(%3s, %-20.20s)", tabpage, callsite)
|
local msg_fault = ""
|
||||||
|
if not globals.WINID_BY_TABID[tabid] then
|
||||||
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
|
msg_fault = "no WINID_BY_TABID"
|
||||||
local tabinfo = globals.TABPAGES[tabpage]
|
elseif not vim.api.nvim_win_is_valid(globals.WINID_BY_TABID[tabid]) then
|
||||||
|
msg_fault = string.format("invalid globals.WINID_BY_TABID[tabid] %d", globals.WINID_BY_TABID[tabid])
|
||||||
local ret = nil
|
|
||||||
|
|
||||||
if not tabinfo then
|
|
||||||
msg = string.format("%s t%d no tabinfo", msg, tabpage)
|
|
||||||
elseif not tabinfo.winnr then
|
|
||||||
msg = string.format("%s t%d no tabinfo.winnr", msg, tabpage)
|
|
||||||
elseif not vim.api.nvim_win_is_valid(tabinfo.winnr) then
|
|
||||||
msg = string.format("%s t%d invalid tabinfo.winnr %d", msg, tabpage, tabinfo.winnr)
|
|
||||||
else
|
else
|
||||||
msg = string.format("%s t%d w%d", msg, tabpage, tabinfo.winnr)
|
global_winid = globals.WINID_BY_TABID[tabid]
|
||||||
ret = tabinfo.winnr
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local winid = self:winid(tabpage, "View:get_winnr")
|
local winid = self:winid(tabid)
|
||||||
if ret ~= winid then
|
|
||||||
if ret then
|
if winid ~= global_winid then
|
||||||
msg = string.format("%s winid_from_bufnr w%s MISMATCH", msg, winid)
|
msg_fault = "MISMATCH"
|
||||||
else
|
|
||||||
msg = string.format("%s winid_from_bufnr w%s STALE", msg, winid)
|
|
||||||
end
|
|
||||||
notify.error(string.format("View:get_winnr w%s View:winnr w%s MISMATCH", ret, winid))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local msg = string.format("View:get_winid(%3s, %-20.20s) globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s %s",
|
||||||
|
tabid_param,
|
||||||
|
callsite,
|
||||||
|
tabid, global_winid,
|
||||||
|
tabid, winid,
|
||||||
|
msg_fault
|
||||||
|
)
|
||||||
|
|
||||||
log.line("dev", "%s", msg)
|
log.line("dev", "%s", msg)
|
||||||
|
|
||||||
return ret
|
if winid ~= global_winid then
|
||||||
else
|
notify.error(msg)
|
||||||
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
|
|
||||||
local tabinfo = globals.TABPAGES[tabpage]
|
|
||||||
if tabinfo and tabinfo.winnr and vim.api.nvim_win_is_valid(tabinfo.winnr) then
|
|
||||||
return tabinfo.winnr
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return winid
|
||||||
|
end
|
||||||
|
--- END multi-instance FF
|
||||||
|
|
||||||
|
-- legacy codepath
|
||||||
|
if global_winid and vim.api.nvim_win_is_valid(global_winid) then
|
||||||
|
return global_winid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -684,26 +690,31 @@ end
|
|||||||
---@return number
|
---@return number
|
||||||
function View:get_bufnr(callsite)
|
function View:get_bufnr(callsite)
|
||||||
local tab = vim.api.nvim_get_current_tabpage()
|
local tab = vim.api.nvim_get_current_tabpage()
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
|
||||||
log.line("dev", "View:get_bufnr(%-20.20s) t%d global b%s member b%s %s",
|
|
||||||
callsite,
|
|
||||||
tab,
|
|
||||||
globals.BUFNR_PER_TAB[tab],
|
|
||||||
self.bufnr_by_tab[tab],
|
|
||||||
(globals.BUFNR_PER_TAB[tab] == self.bufnr_by_tab[tab]) and "" or "MISMATCH")
|
|
||||||
|
|
||||||
if globals.BUFNR_PER_TAB[tab] ~= self.bufnr_by_tab[tab] then
|
--- BEGIN multi-instance FF
|
||||||
notify.error(string.format("View:get_bufnr globals.BUFNR_PER_TAB[%s] b%s view.bufnr_by_tab[%s] b%s MISMATCH",
|
if self.explorer.opts.experimental.multi_instance then
|
||||||
tab, globals.BUFNR_PER_TAB[tab],
|
local msg = string.format("View:get_bufnr(%-20.20s) globals.BUFNR_BY_TABID[%s]=b%s view.bufnr_by_tab[%s]=b%s %s",
|
||||||
tab, self.bufnr_by_tab[tab]
|
callsite,
|
||||||
))
|
tab, globals.BUFNR_BY_TABID[tab],
|
||||||
|
tab, self.bufnr_by_tabid[tab],
|
||||||
|
(globals.BUFNR_BY_TABID[tab] == self.bufnr_by_tabid[tab]) and "" or "MISMATCH"
|
||||||
|
)
|
||||||
|
|
||||||
|
if globals.BUFNR_BY_TABID[tab] ~= self.bufnr_by_tabid[tab] then
|
||||||
|
notify.error(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
log.line("dev", msg)
|
||||||
|
|
||||||
|
return self.bufnr_by_tabid[tab]
|
||||||
end
|
end
|
||||||
return globals.BUFNR_PER_TAB[tab]
|
--- END multi-instance FF
|
||||||
|
|
||||||
|
return globals.BUFNR_BY_TABID[tab]
|
||||||
end
|
end
|
||||||
|
|
||||||
function View:prevent_buffer_override()
|
function View:prevent_buffer_override()
|
||||||
local view_winnr = self:get_winnr(nil, "View:prevent_buffer_override")
|
local view_winid = self:get_winid(nil, "View:prevent_buffer_override")
|
||||||
local view_bufnr = self:get_bufnr("View:prevent_buffer_override")
|
local view_bufnr = self:get_bufnr("View:prevent_buffer_override")
|
||||||
|
|
||||||
-- need to schedule to let the new buffer populate the window
|
-- need to schedule to let the new buffer populate the window
|
||||||
@ -716,18 +727,14 @@ function View:prevent_buffer_override()
|
|||||||
local bufname = vim.api.nvim_buf_get_name(curbuf)
|
local bufname = vim.api.nvim_buf_get_name(curbuf)
|
||||||
|
|
||||||
if not bufname:match("NvimTree") then
|
if not bufname:match("NvimTree") then
|
||||||
for i, tabpage in ipairs(globals.TABPAGES) do
|
for i, winid in ipairs(globals.WINID_BY_TABID) do
|
||||||
if tabpage.winnr == view_winnr then
|
if winid == view_winid then
|
||||||
if self.explorer.opts.experimental.multi_instance then
|
globals.WINID_BY_TABID[i] = nil
|
||||||
log.line("dev", "View:prevent_buffer_override() t%d w%d clearing", i, view_winnr)
|
|
||||||
end
|
|
||||||
|
|
||||||
globals.TABPAGES[i] = nil
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if curwin ~= view_winnr or bufname == "" or curbuf == view_bufnr then
|
if curwin ~= view_winid or bufname == "" or curbuf == view_bufnr then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -757,14 +764,14 @@ end
|
|||||||
---@param cwd string|nil
|
---@param cwd string|nil
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function View:is_root_folder_visible(cwd)
|
function View:is_root_folder_visible(cwd)
|
||||||
return cwd ~= "/" and not self.hide_root_folder
|
return cwd ~= "/" and self.explorer.opts.renderer.root_folder_label ~= false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- used on ColorScheme event
|
-- used on ColorScheme event
|
||||||
function View:reset_winhl()
|
function View:reset_winhl()
|
||||||
local winnr = self:get_winnr(nil, "View:reset_winhl1")
|
local winid = self:get_winid(nil, "View:reset_winhl")
|
||||||
if winnr and vim.api.nvim_win_is_valid(winnr) then
|
if winid and vim.api.nvim_win_is_valid(winid) then
|
||||||
vim.wo[self:get_winnr(nil, "View:reset_winhl2")].winhl = appearance.WIN_HL
|
vim.wo[winid].winhl = appearance.WIN_HL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -774,6 +781,11 @@ function View:is_width_determined()
|
|||||||
return type(self.width) ~= "function"
|
return type(self.width) ~= "function"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- These are needed as they are populated only by the user, not configuration
|
||||||
|
local DEFAULT_MIN_WIDTH = 30
|
||||||
|
local DEFAULT_MAX_WIDTH = -1
|
||||||
|
local DEFAULT_PADDING = 1
|
||||||
|
|
||||||
---Configure width-related config
|
---Configure width-related config
|
||||||
---@param width string|function|number|table|nil
|
---@param width string|function|number|table|nil
|
||||||
function View:configure_width(width)
|
function View:configure_width(width)
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
-- from View
|
-- from View
|
||||||
TABPAGES = {},
|
WINID_BY_TABID = {},
|
||||||
BUFNR_PER_TAB = {},
|
BUFNR_BY_TABID = {},
|
||||||
CURSORS = {},
|
CURSORS = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ function M.set_target_win()
|
|||||||
|
|
||||||
local id = vim.api.nvim_get_current_win()
|
local id = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
if explorer and id == explorer.view:get_winnr(nil, "lib.set_target_win") then
|
if explorer and id == explorer.view:get_winid(nil, "lib.set_target_win") then
|
||||||
M.target_winid = 0
|
M.target_winid = 0
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -136,7 +136,7 @@ function M.open(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if explorer then
|
if explorer then
|
||||||
explorer.view:restore_tab_state()
|
explorer.view:restore_state()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ local globals = require("nvim-tree.globals")
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- Debugging only.
|
--- Debugging only.
|
||||||
--- Tabs show TABPAGES winnr and BUFNR_PER_TAB bufnr for the tab.
|
--- Tabs show WINID_BY_TABID winid and BUFNR_BY_TABID bufnr for the tab.
|
||||||
--- Orphans for inexistent tab_ids are shown at the right.
|
--- Orphans for inexistent tab_ids are shown at the right.
|
||||||
--- lib.target_winid is always shown at the right next to a close button.
|
--- lib.target_winid is always shown at the right next to a close button.
|
||||||
--- Enable with:
|
--- Enable with:
|
||||||
@ -11,38 +11,38 @@ local M = {}
|
|||||||
--- vim.opt.showtabline = 2
|
--- vim.opt.showtabline = 2
|
||||||
---@return string
|
---@return string
|
||||||
function M.tab_line()
|
function M.tab_line()
|
||||||
local tab_ids = vim.api.nvim_list_tabpages()
|
local tabids = vim.api.nvim_list_tabpages()
|
||||||
local cur_tab_id = vim.api.nvim_get_current_tabpage()
|
local tabid_cur = vim.api.nvim_get_current_tabpage()
|
||||||
|
|
||||||
local bufnr_per_tab = vim.deepcopy(globals.BUFNR_PER_TAB)
|
local bufnr_by_tabid = vim.deepcopy(globals.BUFNR_BY_TABID)
|
||||||
local tabpages = vim.deepcopy(globals.TABPAGES)
|
local winid_by_tabid = vim.deepcopy(globals.WINID_BY_TABID)
|
||||||
|
|
||||||
local tl = "%#TabLine#"
|
local tl = "%#TabLine#"
|
||||||
|
|
||||||
for i, tab_id in ipairs(tab_ids) do
|
for i, tabid in ipairs(tabids) do
|
||||||
-- click to select
|
-- click to select
|
||||||
tl = tl .. "%" .. i .. "T"
|
tl = tl .. "%" .. i .. "T"
|
||||||
|
|
||||||
-- style
|
-- style
|
||||||
if tab_id == cur_tab_id then
|
if tabid == tabid_cur then
|
||||||
tl = tl .. "%#StatusLine#|"
|
tl = tl .. "%#StatusLine#|"
|
||||||
else
|
else
|
||||||
tl = tl .. "|%#TabLine#"
|
tl = tl .. "|%#TabLine#"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- tab_id itself
|
-- tab_id itself
|
||||||
tl = tl .. " t" .. tab_id
|
tl = tl .. " t" .. tabid
|
||||||
|
|
||||||
-- winnr, if present
|
-- winid, if present
|
||||||
local tp = globals.TABPAGES[tab_id]
|
local tp = globals.WINID_BY_TABID[tabid]
|
||||||
if tp then
|
if tp then
|
||||||
tl = tl .. " w" .. (tp.winnr or "nil")
|
tl = tl .. " w" .. (tp or "nil")
|
||||||
else
|
else
|
||||||
tl = tl .. " "
|
tl = tl .. " "
|
||||||
end
|
end
|
||||||
|
|
||||||
-- bufnr, if present
|
-- bufnr, if present
|
||||||
local bpt = globals.BUFNR_PER_TAB[tab_id]
|
local bpt = globals.BUFNR_BY_TABID[tabid]
|
||||||
if bpt then
|
if bpt then
|
||||||
tl = tl .. " b" .. bpt
|
tl = tl .. " b" .. bpt
|
||||||
else
|
else
|
||||||
@ -52,8 +52,8 @@ function M.tab_line()
|
|||||||
tl = tl .. " "
|
tl = tl .. " "
|
||||||
|
|
||||||
-- remove actively mapped
|
-- remove actively mapped
|
||||||
bufnr_per_tab[tab_id] = nil
|
bufnr_by_tabid[tabid] = nil
|
||||||
tabpages[tab_id] = nil
|
winid_by_tabid[tabid] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- close last and reset
|
-- close last and reset
|
||||||
@ -61,13 +61,13 @@ function M.tab_line()
|
|||||||
|
|
||||||
-- collect orphans
|
-- collect orphans
|
||||||
local orphans = {}
|
local orphans = {}
|
||||||
for tab_id, bufnr in pairs(bufnr_per_tab) do
|
for tab_id, bufnr in pairs(bufnr_by_tabid) do
|
||||||
orphans[tab_id] = orphans[tab_id] or {}
|
orphans[tab_id] = orphans[tab_id] or {}
|
||||||
orphans[tab_id].bufnr = bufnr
|
orphans[tab_id].bufnr = bufnr
|
||||||
end
|
end
|
||||||
for tab_id, tp in pairs(tabpages) do
|
for tab_id, tp in pairs(winid_by_tabid) do
|
||||||
orphans[tab_id] = orphans[tab_id] or {}
|
orphans[tab_id] = orphans[tab_id] or {}
|
||||||
orphans[tab_id].winnr = tp.winnr
|
orphans[tab_id].winid = tp
|
||||||
end
|
end
|
||||||
|
|
||||||
-- right-align
|
-- right-align
|
||||||
@ -78,9 +78,9 @@ function M.tab_line()
|
|||||||
-- inexistent tab
|
-- inexistent tab
|
||||||
tl = tl .. "%#error#| t" .. tab_id
|
tl = tl .. "%#error#| t" .. tab_id
|
||||||
|
|
||||||
-- maybe winnr
|
-- maybe winid
|
||||||
if orphan.winnr then
|
if orphan.winid then
|
||||||
tl = tl .. " w" .. (orphan.winnr or "nil")
|
tl = tl .. " w" .. (orphan.winid or "nil")
|
||||||
else
|
else
|
||||||
tl = tl .. " "
|
tl = tl .. " "
|
||||||
end
|
end
|
||||||
|
|||||||
@ -105,24 +105,25 @@ function Renderer:draw()
|
|||||||
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local winid = self.explorer.view:get_winid(nil, "Renderer:draw")
|
||||||
|
|
||||||
local profile = log.profile_start("draw")
|
local profile = log.profile_start("draw")
|
||||||
|
|
||||||
local cursor = vim.api.nvim_win_get_cursor(self.explorer.view:get_winnr(nil, "Renderer:draw1") or 0)
|
local cursor = vim.api.nvim_win_get_cursor(winid or 0)
|
||||||
|
|
||||||
local builder = Builder(self.explorer):build()
|
local builder = Builder(self.explorer):build()
|
||||||
|
|
||||||
self:_draw(bufnr, builder.lines, builder.hl_range_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
self:_draw(bufnr, builder.lines, builder.hl_range_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
||||||
|
|
||||||
if cursor and #builder.lines >= cursor[1] then
|
if cursor and #builder.lines >= cursor[1] then
|
||||||
vim.api.nvim_win_set_cursor(self.explorer.view:get_winnr(nil, "Renderer:draw2") or 0, cursor)
|
vim.api.nvim_win_set_cursor(winid or 0, cursor)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.explorer.view:grow_from_content()
|
self.explorer.view:grow_from_content()
|
||||||
|
|
||||||
log.profile_end(profile)
|
log.profile_end(profile)
|
||||||
|
|
||||||
events._dispatch_on_tree_rendered(bufnr, self.explorer.view:get_winnr(nil, "Renderer:draw3"))
|
events._dispatch_on_tree_rendered(bufnr, winid)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Renderer
|
return Renderer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user