add actions.change_dir.restrict_above_cwd (#1171)
This commit is contained in:
parent
ce463a53ae
commit
2c71ffcc0d
@ -194,6 +194,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
|
|||||||
change_dir = {
|
change_dir = {
|
||||||
enable = true,
|
enable = true,
|
||||||
global = false,
|
global = false,
|
||||||
|
restrict_above_cwd = false,
|
||||||
},
|
},
|
||||||
open_file = {
|
open_file = {
|
||||||
quit_on_open = false,
|
quit_on_open = false,
|
||||||
|
|||||||
@ -163,6 +163,7 @@ function.
|
|||||||
change_dir = {
|
change_dir = {
|
||||||
enable = true,
|
enable = true,
|
||||||
global = false,
|
global = false,
|
||||||
|
restrict_above_cwd = false,
|
||||||
},
|
},
|
||||||
open_file = {
|
open_file = {
|
||||||
quit_on_open = false,
|
quit_on_open = false,
|
||||||
@ -486,6 +487,11 @@ Here is a list of the options available in the setup call:
|
|||||||
type: `boolean`
|
type: `boolean`
|
||||||
default: `false`
|
default: `false`
|
||||||
|
|
||||||
|
- |actions.change_dir.restrict_above_cwd|: restrict changing to a directory
|
||||||
|
above the global current working directory.
|
||||||
|
type: `boolean`
|
||||||
|
default: `false`
|
||||||
|
|
||||||
- |actions.open_file.quit_on_open|: closes the explorer when opening a file.
|
- |actions.open_file.quit_on_open|: closes the explorer when opening a file.
|
||||||
It will also disable preventing a buffer overriding the tree.
|
It will also disable preventing a buffer overriding the tree.
|
||||||
type: `boolean`
|
type: `boolean`
|
||||||
|
|||||||
@ -388,6 +388,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||||||
change_dir = {
|
change_dir = {
|
||||||
enable = true,
|
enable = true,
|
||||||
global = false,
|
global = false,
|
||||||
|
restrict_above_cwd = false,
|
||||||
},
|
},
|
||||||
open_file = {
|
open_file = {
|
||||||
quit_on_open = false,
|
quit_on_open = false,
|
||||||
|
|||||||
@ -7,10 +7,6 @@ local diagnostics = require "nvim-tree.diagnostics"
|
|||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
current_tab = a.nvim_get_current_tabpage(),
|
current_tab = a.nvim_get_current_tabpage(),
|
||||||
options = {
|
|
||||||
global = false,
|
|
||||||
change_cwd = true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function M.fn(name, with_open)
|
function M.fn(name, with_open)
|
||||||
@ -20,6 +16,7 @@ function M.fn(name, with_open)
|
|||||||
|
|
||||||
local foldername = name == ".." and vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h") or name
|
local foldername = name == ".." and vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h") or name
|
||||||
local no_cwd_change = vim.fn.expand(foldername) == core.get_cwd()
|
local no_cwd_change = vim.fn.expand(foldername) == core.get_cwd()
|
||||||
|
or M.options.restrict_above_cwd and foldername < vim.fn.getcwd(-1, -1)
|
||||||
local new_tab = a.nvim_get_current_tabpage()
|
local new_tab = a.nvim_get_current_tabpage()
|
||||||
local is_window = (vim.v.event.scope == "window" or vim.v.event.changed_window) and new_tab == M.current_tab
|
local is_window = (vim.v.event.scope == "window" or vim.v.event.changed_window) and new_tab == M.current_tab
|
||||||
if no_cwd_change or is_window then
|
if no_cwd_change or is_window then
|
||||||
@ -32,7 +29,7 @@ end
|
|||||||
function M.force_dirchange(foldername, with_open)
|
function M.force_dirchange(foldername, with_open)
|
||||||
local ps = log.profile_start("change dir %s", foldername)
|
local ps = log.profile_start("change dir %s", foldername)
|
||||||
|
|
||||||
if M.options.change_cwd and vim.tbl_isempty(vim.v.event) then
|
if M.options.enable and vim.tbl_isempty(vim.v.event) then
|
||||||
if M.options.global then
|
if M.options.global then
|
||||||
vim.cmd("cd " .. vim.fn.fnameescape(foldername))
|
vim.cmd("cd " .. vim.fn.fnameescape(foldername))
|
||||||
else
|
else
|
||||||
@ -51,8 +48,7 @@ function M.force_dirchange(foldername, with_open)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(options)
|
function M.setup(options)
|
||||||
M.options.change_cwd = options.actions.change_dir.enable
|
M.options = options.actions.change_dir
|
||||||
M.options.global = options.actions.change_dir.global
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user