From 66f46b204f16246e99380515adeb38cb64908c23 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 28 Aug 2021 15:07:45 +0200 Subject: [PATCH] fix: change base dir in find file when fname does not start with the path of the root --- lua/nvim-tree.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 5e36cd89..8268442b 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -222,6 +222,12 @@ local function is_file_readable(fname) return true end +local function update_base_dir_with_filepath(filepath) + if not vim.startswith(filepath, lib.Tree.cwd or vim.loop.cwd()) then + lib.change_dir(vim.fn.fnamemodify(filepath, ':p:h')) + end +end + function M.find_file(with_open) local bufname = vim.fn.bufname() local filepath = vim.fn.fnamemodify(bufname, ':p') @@ -230,11 +236,13 @@ function M.find_file(with_open) M.open() view.focus() if not is_file_readable(filepath) then return end + update_base_dir_with_filepath(filepath) lib.set_index_and_redraw(filepath) return end if not is_file_readable(filepath) then return end + update_base_dir_with_filepath(filepath) lib.set_index_and_redraw(filepath) end