* Revert "fix(#3172): live filter exception (#3173)" This reverts commit0a7fcdf3f8. * Revert "refactor(#2826): move view to instanced window class (#3153)" This reverts commit0a06f65bf0. * feat(#3157): add view.cursorlineopt
This commit is contained in:
committed by
GitHub
parent
9b289abd69
commit
a4699c0904
@@ -1,4 +1,5 @@
|
||||
local log = require("nvim-tree.log")
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
|
||||
@@ -13,7 +14,7 @@ local running = {}
|
||||
---@param path string relative or absolute
|
||||
function M.fn(path)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer or not explorer.view:is_visible() then
|
||||
if not explorer or not view.is_visible() then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -83,9 +84,9 @@ function M.fn(path)
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
if found and explorer.view:is_visible() then
|
||||
if found and view.is_visible() then
|
||||
explorer.renderer:draw()
|
||||
explorer.view:set_cursor({ line, 0 })
|
||||
view.set_cursor({ line, 0 })
|
||||
end
|
||||
|
||||
running[path_real] = false
|
||||
|
||||
@@ -31,8 +31,6 @@ local Clipboard = Class:extend()
|
||||
---@protected
|
||||
---@param args ClipboardArgs
|
||||
function Clipboard:new(args)
|
||||
args.explorer:log_new("Clipboard")
|
||||
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.data = {
|
||||
@@ -44,10 +42,6 @@ function Clipboard:new(args)
|
||||
self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1"
|
||||
end
|
||||
|
||||
function Clipboard:destroy()
|
||||
self.explorer:log_destroy("Clipboard")
|
||||
end
|
||||
|
||||
---@param source string
|
||||
---@param destination string
|
||||
---@return boolean
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local events = require("nvim-tree.events")
|
||||
local view = require("nvim-tree.view")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
@@ -13,12 +14,10 @@ local M = {
|
||||
|
||||
---@param windows integer[]
|
||||
local function close_windows(windows)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
-- Prevent from closing when the win count equals 1 or 2,
|
||||
-- where the win to remove could be the last opened.
|
||||
-- For details see #2503.
|
||||
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
|
||||
if view.View.float.enable and #vim.api.nvim_list_wins() < 3 then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -31,17 +30,16 @@ end
|
||||
|
||||
---@param absolute_path string
|
||||
local function clear_buffer(absolute_path)
|
||||
local explorer = core.get_explorer()
|
||||
local bufs = vim.fn.getbufinfo({ bufloaded = 1, buflisted = 1 })
|
||||
for _, buf in pairs(bufs) do
|
||||
if buf.name == absolute_path then
|
||||
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 view.View.float.enable) then
|
||||
vim.api.nvim_set_current_win(buf.windows[1])
|
||||
vim.cmd(":bn")
|
||||
end
|
||||
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
|
||||
if explorer and not explorer.view.float.quit_on_focus_loss then
|
||||
if not view.View.float.quit_on_focus_loss then
|
||||
vim.api.nvim_set_current_win(tree_winnr)
|
||||
end
|
||||
if M.config.actions.remove_file.close_window then
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
local diagnostics = require("nvim-tree.diagnostics")
|
||||
|
||||
@@ -66,9 +67,9 @@ local function move(explorer, where, what, skip_gitignored)
|
||||
end
|
||||
|
||||
if nex then
|
||||
explorer.view:set_cursor({ nex, 0 })
|
||||
view.set_cursor({ nex, 0 })
|
||||
elseif vim.o.wrapscan and first then
|
||||
explorer.view:set_cursor({ first, 0 })
|
||||
view.set_cursor({ first, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -188,13 +189,13 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
|
||||
|
||||
-- 4.3)
|
||||
if node_init.name == ".." then -- root node
|
||||
explorer.view:set_cursor({ 1, 0 }) -- move to root node (position 1)
|
||||
view.set_cursor({ 1, 0 }) -- move to root node (position 1)
|
||||
else
|
||||
local node_init_line = utils.find_node_line(node_init)
|
||||
if node_init_line < 0 then
|
||||
return
|
||||
end
|
||||
explorer.view:set_cursor({ node_init_line, 0 })
|
||||
view.set_cursor({ node_init_line, 0 })
|
||||
end
|
||||
|
||||
-- 4.4)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
@@ -24,7 +25,7 @@ function M.fn(should_close)
|
||||
local parent = (node:get_parent_of_group() or node).parent
|
||||
|
||||
if not parent or not parent.parent then
|
||||
node.explorer.view:set_cursor({ 1, 0 })
|
||||
view.set_cursor({ 1, 0 })
|
||||
return
|
||||
end
|
||||
|
||||
@@ -32,7 +33,7 @@ function M.fn(should_close)
|
||||
return n.absolute_path == parent.absolute_path
|
||||
end)
|
||||
|
||||
node.explorer.view:set_cursor({ line + 1, 0 })
|
||||
view.set_cursor({ line + 1, 0 })
|
||||
if should_close then
|
||||
parent.open = false
|
||||
parent.explorer.renderer:draw()
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
local lib = require("nvim-tree.lib")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
local full_name = require("nvim-tree.renderer.components.full-name")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -20,10 +20,9 @@ end
|
||||
---Get all windows in the current tabpage that aren't NvimTree.
|
||||
---@return table with valid win_ids
|
||||
local function usable_win_ids()
|
||||
local explorer = core.get_explorer()
|
||||
local tabpage = vim.api.nvim_get_current_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 = view.get_winnr(tabpage)
|
||||
|
||||
return vim.tbl_filter(function(id)
|
||||
local bufid = vim.api.nvim_win_get_buf(id)
|
||||
@@ -194,10 +193,7 @@ end
|
||||
|
||||
local function open_file_in_tab(filename)
|
||||
if M.quit_on_open then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:close(nil, "open-file.open_file_in_tab")
|
||||
end
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
@@ -207,10 +203,7 @@ end
|
||||
|
||||
local function drop(filename)
|
||||
if M.quit_on_open then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:close(nil, "open-file.drop")
|
||||
end
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
@@ -220,10 +213,7 @@ end
|
||||
|
||||
local function tab_drop(filename)
|
||||
if M.quit_on_open then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:close(nil, "open-file.tab_drop")
|
||||
end
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
@@ -244,10 +234,7 @@ local function on_preview(buf_loaded)
|
||||
once = true,
|
||||
})
|
||||
end
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:focus()
|
||||
end
|
||||
view.focus()
|
||||
end
|
||||
|
||||
local function get_target_winid(mode)
|
||||
@@ -292,8 +279,6 @@ local function set_current_win_no_autocmd(winid, autocmd)
|
||||
end
|
||||
|
||||
local function open_in_new_window(filename, mode)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if type(mode) ~= "string" then
|
||||
mode = ""
|
||||
end
|
||||
@@ -316,11 +301,7 @@ local function open_in_new_window(filename, mode)
|
||||
end, vim.api.nvim_list_wins())
|
||||
|
||||
local create_new_window = #win_ids == 1 -- This implies that the nvim-tree window is the only one
|
||||
|
||||
local new_window_side = "belowright"
|
||||
if explorer and (explorer.view.side == "right") then
|
||||
new_window_side = "aboveleft"
|
||||
end
|
||||
local new_window_side = (view.View.side == "right") and "aboveleft" or "belowright"
|
||||
|
||||
-- Target is invalid: create new window
|
||||
if not vim.tbl_contains(win_ids, target_winid) then
|
||||
@@ -352,7 +333,7 @@ local function open_in_new_window(filename, mode)
|
||||
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 view.View.float.enable then
|
||||
-- ignore "WinLeave" autocmd on preview
|
||||
-- because the registered "WinLeave"
|
||||
-- will kill the floating window immediately
|
||||
@@ -392,12 +373,7 @@ local function is_already_loaded(filename)
|
||||
end
|
||||
|
||||
local function edit_in_current_buf(filename)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if explorer then
|
||||
explorer.view:abandon_current_window()
|
||||
end
|
||||
|
||||
require("nvim-tree.view").abandon_current_window()
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
@@ -408,8 +384,6 @@ end
|
||||
---@param filename string
|
||||
---@return nil
|
||||
function M.fn(mode, filename)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if type(mode) ~= "string" then
|
||||
mode = ""
|
||||
end
|
||||
@@ -444,16 +418,16 @@ function M.fn(mode, filename)
|
||||
vim.bo.bufhidden = ""
|
||||
end
|
||||
|
||||
if M.resize_window and explorer then
|
||||
explorer.view:resize()
|
||||
if M.resize_window then
|
||||
view.resize()
|
||||
end
|
||||
|
||||
if mode == "preview" or mode == "preview_no_picker" then
|
||||
return on_preview(buf_loaded)
|
||||
end
|
||||
|
||||
if M.quit_on_open and explorer then
|
||||
explorer.view:close(nil, "open-file.fn")
|
||||
if M.quit_on_open then
|
||||
view.close()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
|
||||
if should_change_dir() then
|
||||
cd(M.options.global, foldername)
|
||||
end
|
||||
core.init(foldername, "change-dir")
|
||||
core.init(foldername)
|
||||
end
|
||||
|
||||
if should_open_view then
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -40,12 +41,11 @@ function M.fn(opts)
|
||||
return
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer and explorer.view:is_visible() then
|
||||
if view.is_visible() then
|
||||
-- focus
|
||||
if opts.focus then
|
||||
lib.set_target_win()
|
||||
explorer.view:focus()
|
||||
view.focus()
|
||||
end
|
||||
elseif opts.open then
|
||||
-- open
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -23,12 +23,10 @@ function M.fn(opts)
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if explorer and explorer.view:is_visible() then
|
||||
if view.is_visible() then
|
||||
-- focus
|
||||
lib.set_target_win()
|
||||
explorer.view:focus()
|
||||
view.focus()
|
||||
else
|
||||
-- open
|
||||
lib.open({
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local M = {}
|
||||
|
||||
---Resize the tree, persisting the new size.
|
||||
---@param opts ApiTreeResizeOpts|nil
|
||||
function M.fn(opts)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
if opts == nil then
|
||||
-- reset to config values
|
||||
explorer.view:configure_width()
|
||||
explorer.view:resize()
|
||||
view.configure_width()
|
||||
view.resize()
|
||||
return
|
||||
end
|
||||
|
||||
@@ -21,19 +16,19 @@ function M.fn(opts)
|
||||
local width_cfg = options.width
|
||||
|
||||
if width_cfg ~= nil then
|
||||
explorer.view:configure_width(width_cfg)
|
||||
explorer.view:resize()
|
||||
view.configure_width(width_cfg)
|
||||
view.resize()
|
||||
return
|
||||
end
|
||||
|
||||
if not explorer.view:is_width_determined() then
|
||||
if not view.is_width_determined() then
|
||||
-- {absolute} and {relative} do nothing when {width} is a function.
|
||||
return
|
||||
end
|
||||
|
||||
local absolute = options.absolute
|
||||
if type(absolute) == "number" then
|
||||
explorer.view:resize(absolute)
|
||||
view.resize(absolute)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -44,7 +39,7 @@ function M.fn(opts)
|
||||
relative_size = "+" .. relative_size
|
||||
end
|
||||
|
||||
explorer.view:resize(relative_size)
|
||||
view.resize(relative_size)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -10,8 +10,6 @@ local M = {}
|
||||
---@param cwd boolean|nil legacy -> opts.path
|
||||
---@param bang boolean|nil legacy -> opts.update_root
|
||||
function M.fn(opts, no_focus, cwd, bang)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
-- legacy arguments
|
||||
if type(opts) == "boolean" then
|
||||
opts = {
|
||||
@@ -42,9 +40,9 @@ function M.fn(opts, no_focus, cwd, bang)
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
if explorer and explorer.view:is_visible() then
|
||||
if view.is_visible() then
|
||||
-- close
|
||||
explorer.view:close(nil, "toggle.fn")
|
||||
view.close()
|
||||
else
|
||||
-- open
|
||||
lib.open({
|
||||
|
||||
Reference in New Issue
Block a user