From 0ed31e065e3d8db5cff3706035e139c349b55ab4 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Tue, 18 Feb 2020 16:06:05 +0100 Subject: [PATCH] refresh tree when changing fs --- README.md | 2 +- lua/lib/file.lua | 4 ++-- lua/lib/state.lua | 8 +++----- lua/tree.lua | 3 +-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bb9b05f6..8255ec88 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ - [x] change directory base - [x] add / rename / delete file in directory -- [ ] update tree when altering the FS +- [x] update tree when altering the FS - [x] syntax highlighting ([exa](https://github.com/ogham/exa) like) and file icons with vim-devicons - [ ] simple git integration (color of file changing when staged/changed) diff --git a/lua/lib/file.lua b/lua/lib/file.lua index 109957e1..570618ee 100644 --- a/lua/lib/file.lua +++ b/lua/lib/file.lua @@ -1,8 +1,8 @@ local api = vim.api local buf, win local system = function(v) api.nvim_call_function('system', { v }) end --- local update_tree_view = require '' -local update_tree_state = require 'lib/state'.update_tree +local update_tree_view = require 'lib/winutils'.update_view +local update_tree_state = require 'lib/state'.refresh_tree local EDIT_FILE = nil diff --git a/lua/lib/state.lua b/lua/lib/state.lua index 1878ea43..50169877 100644 --- a/lua/lib/state.lua +++ b/lua/lib/state.lua @@ -1,5 +1,6 @@ local api = vim.api local function syslist(v) return api.nvim_call_function('systemlist', { v }) end +local get_root_path = require 'lib/conf'.get_root_path local Tree = {} @@ -56,7 +57,8 @@ local function create_nodes(path, depth, dirs) return sort_dirs(tree) end -local function init_tree(ROOT_PATH) +local function init_tree() + local ROOT_PATH = get_root_path() Tree = create_nodes(ROOT_PATH, 0, list_dirs()) if ROOT_PATH ~= '/' then table.insert(Tree, 1, { @@ -90,10 +92,6 @@ local function refresh_tree() for j, n in pairs(create_nodes(path, node.depth + 1, dirs)) do table.insert(Tree, i + j, n) end - -- TODO: maybe extract this function to make a recursive call to reexplore the list - -- when adding a new list of dirs to make sure we go to the bottom of the opened structure - -- otherwise it might close opened directories - -- im not sure how lua behaves in this matter end end end diff --git a/lua/tree.lua b/lua/tree.lua index 3ba2cbfc..1d990d7c 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -20,10 +20,9 @@ local set_mappings = winutils.set_mappings local conf = require 'lib/conf' local set_root_path = conf.set_root_path -local get_root_path = conf.get_root_path local get_cwd = conf.get_cwd -init_tree(get_root_path()) +init_tree() local function toggle() if is_win_open() == true then