neo-tree.nvim
neo-tree.nvim copied to clipboard
`:Neotree reveal dir=???` should not ask to change cwd
If the user explicitly passed a directory to use as root, the command should not attempt to change the cwd automatically.
I see what's wrong, you found a bug. If you answer
n
to that prompt it would work correctly. The problem here is that the check for whether a reveled file is in the current working directory does not check the directory you requested as the root, it only checks what is your current working directory. I'll open a new issue for this.
Originally posted by @cseickel in https://github.com/nvim-neo-tree/neo-tree.nvim/issues/610#issuecomment-1488439343
I believe the problem is the path is not updated set when it read: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/230ff118613fa07138ba579b89d13ec2201530b9/lua/neo-tree/command/init.lua#L210
The path is only updated later in the do_show_or_focus
method.
I find I get decent behavior from this workaround
-- Copyright 2023 Google LLC.
-- SPDX-License-Identifier: Apache-2.0
function open_tree(args)
local manager = require("neo-tree.sources.manager")
local reveal_file = manager.get_path_to_reveal()
if args.dir then
-- Hack to work around a bug in neo-tree where it changes path too late for reveal
state = manager.get_state(args.source, nil, nil)
manager.navigate(state, args.dir, reveal_file, nil, false)
end
require("neo-tree.command").execute({
dir = args.dir,
source = args.source,
reveal_file = reveal_file,
reveal_force_cwd = true,
})
end