Skip to content

Make create/paste add files to closed folders #1802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ Subsequent calls to setup will replace the previous configuration.
>
require("nvim-tree").setup { -- BEGIN_DEFAULT_OPTS
auto_reload_on_write = true,
create_in_closed_folder = false,
disable_netrw = false,
hijack_cursor = false,
hijack_netrw = true,
Expand Down Expand Up @@ -434,11 +433,6 @@ in some scenarios (eg using vim startify).
Reloads the explorer every time a buffer is written to.
Type: `boolean`, Default: `true`

*nvim-tree.create_in_closed_folder*
Creating a file when the cursor is on a closed folder will set the
path to be inside the closed folder, otherwise the parent folder.
Type: `boolean`, Default: `false`

*nvim-tree.sort_by*
Changes how files within the same directory are sorted.
Can be one of `name`, `case_sensitive`, `modification_time`, `extension` or a
Expand Down
1 change: 0 additions & 1 deletion lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
auto_reload_on_write = true,
create_in_closed_folder = false,
disable_netrw = false,
hijack_cursor = false,
hijack_netrw = true,
Expand Down
3 changes: 0 additions & 3 deletions lua/nvim-tree/actions/fs/copy-paste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ local function do_paste(node, action_type, action_fn)
return
end
local is_dir = stats and stats.type == "directory"

if not is_dir then
destination = vim.fn.fnamemodify(destination, ":p:h")
elseif not node.open then
destination = vim.fn.fnamemodify(destination, ":p:h:h")
end

for _, _node in ipairs(clip) do
Expand Down
4 changes: 1 addition & 3 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ local function get_num_nodes(iter)
end

local function get_containing_folder(node)
local is_open = M.create_in_closed_folder or node.open
if node.nodes ~= nil and is_open then
if node.nodes ~= nil then
return utils.path_add_trailing(node.absolute_path)
end
local node_name_size = #(node.name or "")
Expand Down Expand Up @@ -113,7 +112,6 @@ function M.fn(node)
end

function M.setup(opts)
M.create_in_closed_folder = opts.create_in_closed_folder
M.enable_reload = not opts.filesystem_watchers.enable
end

Expand Down
11 changes: 5 additions & 6 deletions lua/nvim-tree/legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,6 @@ local g_migrations = {
o.respect_buf_cwd = vim.g.nvim_tree_respect_buf_cwd == 1
end
end,

nvim_tree_create_in_closed_folder = function(o)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's time to remove the g: legacy. Maybe after merging this...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with that - it's been long enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic!

if o.create_in_closed_folder == nil then
o.create_in_closed_folder = vim.g.nvim_tree_create_in_closed_folder == 1
end
end,
}

local function refactored(opts)
Expand Down Expand Up @@ -309,6 +303,11 @@ local function removed(opts)
notify.warn "focus_empty_on_setup has been removed and will be replaced by a new startup configuration. Please remove this option. See https://bit.ly/3yJch2T"
opts.focus_empty_on_setup = nil
end

if opts.create_in_closed_folder then
notify.warn "create_in_closed_folder has been removed and is now the default behaviour. You may use api.fs.create to add a file under your desired node."
end
opts.create_in_closed_folder = nil
end

function M.migrate_legacy_options(opts)
Expand Down