fix: tree redraw, always expand nodes

This commit is contained in:
əlemi 2024-09-17 18:43:45 +02:00
parent eda004423e
commit 16f9bd77fd
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 9 additions and 10 deletions

View file

@ -124,13 +124,18 @@ M.update_state = function(state)
} }
} }
state.force_open_folders = true
state.default_expanded_nodes = {}
if CODEMP.workspace ~= nil then if CODEMP.workspace ~= nil then
local ws_section = new_root("#" .. CODEMP.workspace.name) 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 for i, path in ipairs(CODEMP.workspace:filetree()) do
table.insert(ws_section.children, new_item(CODEMP.workspace.name, path)) table.insert(ws_section.children, new_item(CODEMP.workspace.name, path))
end end
local usr_section = new_root("users") local usr_section = new_root("users")
table.insert(state.default_expanded_nodes, usr_section.id)
for user, buffer in pairs(buf_manager.users) do for user, buffer in pairs(buf_manager.users) do
table.insert(usr_section.children, new_user(CODEMP.workspace.name, user)) table.insert(usr_section.children, new_user(CODEMP.workspace.name, user))
end end
@ -143,6 +148,7 @@ M.update_state = function(state)
if CODEMP.client ~= nil then if CODEMP.client ~= nil then
local ws_section = new_root("workspaces") local ws_section = new_root("workspaces")
table.insert(state.default_expanded_nodes, ws_section.id)
for _, ws in ipairs(CODEMP.available) do for _, ws in ipairs(CODEMP.available) do
table.insert(ws_section.children, new_workspace(ws.name, ws.owned)) table.insert(ws_section.children, new_workspace(ws.name, ws.owned))
end end
@ -150,6 +156,7 @@ M.update_state = function(state)
table.insert(root, ws_section) table.insert(root, ws_section)
local status_section = new_root("client") 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("id", CODEMP.client.id))
table.insert(status_section.children, new_entry("name", CODEMP.client.username)) table.insert(status_section.children, new_entry("name", CODEMP.client.username))
@ -163,13 +170,6 @@ M.update_state = function(state)
end end
renderer.show_nodes(root, state) 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 end
return M return M

View file

@ -38,7 +38,6 @@ M.open = function(state, path, extra)
if CODEMP.workspace == nil then if CODEMP.workspace == nil then
ws_manager.join(selected.name) ws_manager.join(selected.name)
end end
manager.refresh("codemp")
return return
end end
if selected.type == "buffer" then if selected.type == "buffer" then
@ -108,7 +107,6 @@ M.delete = function(state, path, extra)
if input == nil then return end if input == nil then return end
if not vim.startswith("y", string.lower(input)) then return end if not vim.startswith("y", string.lower(input)) then return end
ws_manager.leave() ws_manager.leave()
manager.refresh("codemp")
end) end)
elseif selected.type == "buffer" then elseif selected.type == "buffer" then
if CODEMP.workspace == nil then error("join a workspace first") end 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) vim.ui.input({ prompt = "new workspace name" }, function(input)
if input == nil or input == "" then return end if input == nil or input == "" then return end
CODEMP.client:create_workspace(input):and_then(function () CODEMP.client:create_workspace(input):and_then(function ()
manager.refresh("codemp")
require('codemp.workspace').list() require('codemp.workspace').list()
end) end)
end) end)
@ -159,7 +158,6 @@ M.add = function(state, path, extra)
end) end)
end) end)
end end
manager.refresh("codemp")
end end
cc._add_common_commands(M) cc._add_common_commands(M)

View file

@ -146,6 +146,7 @@ local function leave()
CODEMP.client:leave_workspace(CODEMP.workspace.name) CODEMP.client:leave_workspace(CODEMP.workspace.name)
print(" -- left workspace") print(" -- left workspace")
CODEMP.workspace = nil CODEMP.workspace = nil
require('codemp.window').update()
end end
return { return {