aboutsummaryrefslogtreecommitdiff
path: root/plugins/workspace.lua
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-06-17 16:07:52 +0100
committerrxi <rxi@users.noreply.github.com>2020-06-17 16:07:52 +0100
commit408d6d0eb3a216e33755e206ca967e06ae7ac0c2 (patch)
tree39bf3e5559fd34dc80aee974136bfaa2dca7c47a /plugins/workspace.lua
parent29669bdcb0cd8a1601be4f917aa432385e5ad445 (diff)
downloadlite-xl-plugins-408d6d0eb3a216e33755e206ca967e06ae7ac0c2.tar.gz
lite-xl-plugins-408d6d0eb3a216e33755e206ca967e06ae7ac0c2.zip
Added retaining of the active_view to workspace plugin
Diffstat (limited to 'plugins/workspace.lua')
-rw-r--r--plugins/workspace.lua23
1 files changed, 18 insertions, 5 deletions
diff --git a/plugins/workspace.lua b/plugins/workspace.lua
index b40ab4b..8f8dfcc 100644
--- a/plugins/workspace.lua
+++ b/plugins/workspace.lua
@@ -41,6 +41,7 @@ local function save_view(view)
if mt == DocView then
return {
type = "doc",
+ active = (core.active_view == view),
filename = view.doc.filename,
selection = { view.doc:get_selection() },
scroll = { x = view.scroll.to.x, y = view.scroll.to.y },
@@ -49,7 +50,11 @@ local function save_view(view)
end
for name, mod in pairs(package.loaded) do
if mod == mt then
- return { type = "view", module = name }
+ return {
+ type = "view",
+ active = (core.active_view == view),
+ module = name
+ }
end
end
end
@@ -98,17 +103,22 @@ end
local function load_node(node, t)
if t.type == "leaf" then
+ local res
for _, v in ipairs(t.views) do
- node:add_view(load_view(v))
+ local view = load_view(v)
+ if v.active then res = view end
+ node:add_view(view)
end
if t.active_view then
node:set_active_view(node.views[t.active_view])
end
+ return res
else
node:split(t.type == "hsplit" and "right" or "down")
node.divider = t.divider
- load_node(node.a, t.a)
- load_node(node.b, t.b)
+ local res1 = load_node(node.a, t.a)
+ local res2 = load_node(node.b, t.b)
+ return res1 or res2
end
end
@@ -126,7 +136,10 @@ local function load_workspace()
os.remove(workspace_filename)
if ok then
local root = get_unlocked_root(core.root_view.root_node)
- load_node(root, t)
+ local active_view = load_node(root, t)
+ if active_view then
+ core.set_active_view(active_view)
+ end
end
end