From 16f9bd77fd6d0ab49467919f96e738a491843c2d Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 17 Sep 2024 18:43:45 +0200 Subject: [PATCH] fix: tree redraw, always expand nodes --- lua/codemp/neo-tree/bridge.lua | 14 +++++++------- lua/codemp/neo-tree/commands.lua | 4 +--- lua/codemp/workspace.lua | 1 + 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lua/codemp/neo-tree/bridge.lua b/lua/codemp/neo-tree/bridge.lua index d1e2602..f5851be 100644 --- a/lua/codemp/neo-tree/bridge.lua +++ b/lua/codemp/neo-tree/bridge.lua @@ -124,13 +124,18 @@ M.update_state = function(state) } } + state.force_open_folders = true + state.default_expanded_nodes = {} + if CODEMP.workspace ~= nil then local ws_section = new_root("#" .. CODEMP.workspace.name) + table.insert(state.default_expanded_nodes, ws_section.id) for i, path in ipairs(CODEMP.workspace:filetree()) do table.insert(ws_section.children, new_item(CODEMP.workspace.name, path)) end local usr_section = new_root("users") + table.insert(state.default_expanded_nodes, usr_section.id) for user, buffer in pairs(buf_manager.users) do table.insert(usr_section.children, new_user(CODEMP.workspace.name, user)) end @@ -143,6 +148,7 @@ M.update_state = function(state) if CODEMP.client ~= nil then local ws_section = new_root("workspaces") + table.insert(state.default_expanded_nodes, ws_section.id) for _, ws in ipairs(CODEMP.available) do table.insert(ws_section.children, new_workspace(ws.name, ws.owned)) end @@ -150,6 +156,7 @@ M.update_state = function(state) table.insert(root, ws_section) local status_section = new_root("client") + table.insert(state.default_expanded_nodes, status_section.id) table.insert(status_section.children, new_entry("id", CODEMP.client.id)) table.insert(status_section.children, new_entry("name", CODEMP.client.username)) @@ -163,13 +170,6 @@ M.update_state = function(state) end renderer.show_nodes(root, state) - - local new_state = "disconnected" - if CODEMP.client ~= nil then new_state = "connected" end - if CODEMP.workspace ~= nil then new_state = "joined" end - - if last_state ~= new_state then expand(state.tree) end - last_state = new_state end return M diff --git a/lua/codemp/neo-tree/commands.lua b/lua/codemp/neo-tree/commands.lua index a280ab2..e549ee7 100644 --- a/lua/codemp/neo-tree/commands.lua +++ b/lua/codemp/neo-tree/commands.lua @@ -38,7 +38,6 @@ M.open = function(state, path, extra) if CODEMP.workspace == nil then ws_manager.join(selected.name) end - manager.refresh("codemp") return end if selected.type == "buffer" then @@ -108,7 +107,6 @@ M.delete = function(state, path, extra) if input == nil then return end if not vim.startswith("y", string.lower(input)) then return end ws_manager.leave() - manager.refresh("codemp") end) elseif selected.type == "buffer" then if CODEMP.workspace == nil then error("join a workspace first") end @@ -147,6 +145,7 @@ M.add = function(state, path, extra) vim.ui.input({ prompt = "new workspace name" }, function(input) if input == nil or input == "" then return end CODEMP.client:create_workspace(input):and_then(function () + manager.refresh("codemp") require('codemp.workspace').list() end) end) @@ -159,7 +158,6 @@ M.add = function(state, path, extra) end) end) end - manager.refresh("codemp") end cc._add_common_commands(M) diff --git a/lua/codemp/workspace.lua b/lua/codemp/workspace.lua index dab90cc..17d99f0 100644 --- a/lua/codemp/workspace.lua +++ b/lua/codemp/workspace.lua @@ -146,6 +146,7 @@ local function leave() CODEMP.client:leave_workspace(CODEMP.workspace.name) print(" -- left workspace") CODEMP.workspace = nil + require('codemp.window').update() end return {