Skip to content

Commit 242dc82

Browse files
authored
fix: handle reveal_force_cwd correctly when cwd doesn't need to change (#215)
1 parent 19903c5 commit 242dc82

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

lua/neo-tree/command/init.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,10 @@ handle_reveal = function(args, state)
175175
if cwd == nil then
176176
cwd = manager.get_cwd(state)
177177
end
178-
if args.reveal_force_cwd then
179-
if not utils.is_subpath(cwd, path) then
180-
args.dir, _ = utils.split_path(path)
181-
do_show_or_focus(args, state, true)
182-
return
183-
end
178+
if args.reveal_force_cwd and not utils.is_subpath(cwd, path) then
179+
args.dir, _ = utils.split_path(path)
180+
do_show_or_focus(args, state, true)
181+
return
184182
elseif not utils.is_subpath(cwd, path) then
185183
-- force was not specified, so we need to ask the user
186184
cwd, _ = utils.split_path(path)

tests/helpers/util.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
local utils = {}
22

33
local Path = require("plenary.path")
4-
local testdir = Path:new(vim.env.TMPDIR or "/tmp", "neo-tree-testing"):absolute()
4+
-- Resolve for two reasons.
5+
-- 1. Follow any symlinks which make comparing paths fail. (on macOS, TMPDIR can be under /var which is symlinked to
6+
-- /private/var)
7+
-- 2. Remove any double separators (on macOS TMPDIR can end in a trailing / which absolute doesn't remove, this should
8+
-- be coverted by https://github.com/nvim-lua/plenary.nvim/issues/330).
9+
local testdir = vim.fn.resolve(Path:new(vim.env.TMPDIR or "/tmp", "neo-tree-testing"):absolute())
510

611
local function rm_test_dir()
712
if vim.fn.isdirectory(testdir) == 1 then

tests/neo-tree/command/command_current_spec.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local Path = require('plenary.path')
12
local util = require("tests.helpers.util")
23
local verify = require("tests.helpers.verify")
34
local config = require("neo-tree").config
@@ -50,14 +51,20 @@ describe("Command", function()
5051
verify.buf_name_is(testfile)
5152
end)
5253

53-
it("`:Neotree current reveal_force_cwd reveal_file=xyz` should reveal file current window", function()
54+
it("`:Neotree current reveal_force_cwd reveal_file=xyz` should reveal file current window if cwd is not a parent of file", function()
5455
vim.cmd("cd ~")
55-
vim.cmd("tcd ~")
56-
vim.cmd("lcd ~")
5756
local testfile = fs.lookup["deepfile2"].abspath
5857
local cmd = "Neotree current reveal_force_cwd reveal_file=" .. testfile
5958
run_in_current_command(cmd, testfile)
6059
end)
60+
61+
it("`:Neotree current reveal_force_cwd reveal_file=xyz` should reveal file current window if cwd is a parent of file", function()
62+
local testfile = fs.lookup["deepfile2"].abspath
63+
local testfile_dir = Path:new(testfile):parent().filename
64+
vim.cmd(string.format("cd %s", testfile_dir))
65+
local cmd = "Neotree current reveal_force_cwd reveal_file=" .. testfile
66+
run_in_current_command(cmd, testfile)
67+
end)
6168
end)
6269

6370
util.teardown_test_fs()

0 commit comments

Comments
 (0)