save last command based on layout name
This commit is contained in:
parent
602ebbf735
commit
16a6f77ea4
32
editor.lua
32
editor.lua
|
@ -109,9 +109,21 @@ local function restore_data(data)
|
|||
print("cannot read history from " .. data.history_file)
|
||||
else
|
||||
data.cmds = {}
|
||||
data.last_cmd = {}
|
||||
local last_layout_name
|
||||
for line in file:lines() do
|
||||
print("restore cmd " .. line)
|
||||
data.cmds[#data.cmds + 1] = line
|
||||
if line:sub(1, 1) == "+" then
|
||||
last_layout_name = line:sub(2, #line)
|
||||
else
|
||||
if last_layout_name ~= nil then
|
||||
print("restore last cmd " .. line .. " for " .. last_layout_name)
|
||||
data.last_cmd[last_layout_name] = line
|
||||
last_layout_name = nil
|
||||
else
|
||||
print("restore cmd " .. line)
|
||||
data.cmds[#data.cmds + 1] = line
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -132,6 +144,10 @@ local function create(data)
|
|||
data.cmds = {}
|
||||
end
|
||||
|
||||
if data.last_cmd == nil then
|
||||
data.last_cmd = {}
|
||||
end
|
||||
|
||||
local gap = data.gap or 0
|
||||
|
||||
local closed_areas
|
||||
|
@ -530,6 +546,7 @@ local function create(data)
|
|||
end
|
||||
-- bring the current cmd to the front
|
||||
data.cmds[#data.cmds + 1] = current_cmd
|
||||
data.last_cmd[layout.name] = current_cmd
|
||||
|
||||
if data.history_file then
|
||||
local file, err = io.open(data.history_file, "w")
|
||||
|
@ -540,6 +557,10 @@ local function create(data)
|
|||
print("save cmd " .. data.cmds[i])
|
||||
file:write(data.cmds[i] .. "\n")
|
||||
end
|
||||
for name, cmd in pairs(data.last_cmd) do
|
||||
print("save last cmd " .. cmd .. " for " .. name)
|
||||
file:write("+" .. name .. "\n" .. cmd .. "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -616,15 +637,14 @@ local function create(data)
|
|||
end
|
||||
)
|
||||
layout.cmd = cmd
|
||||
data.last_cmd[layout.name] = cmd
|
||||
layout.set_regions(areas_with_gap)
|
||||
api.layout.arrange(screen)
|
||||
end
|
||||
|
||||
local function try_restore_last(layout, screen)
|
||||
local index = #data.cmds
|
||||
if index == 0 then return end
|
||||
|
||||
set_by_cmd(layout, screen, data.cmds[#data.cmds])
|
||||
if data.last_cmd[layout.name] == nil then return end
|
||||
set_by_cmd(layout, screen, data.last_cmd[layout.name])
|
||||
end
|
||||
|
||||
return {
|
||||
|
|
|
@ -69,7 +69,7 @@ function do_arrange(p, priv)
|
|||
end
|
||||
end
|
||||
|
||||
function create()
|
||||
function create(name)
|
||||
local priv = { regions = {} }
|
||||
|
||||
local function set_regions(regions)
|
||||
|
@ -110,6 +110,7 @@ function create()
|
|||
end
|
||||
|
||||
return {
|
||||
name = name,
|
||||
arrange = function (p) do_arrange(p, priv) end,
|
||||
get_region_count = function () return #priv.regions end,
|
||||
set_regions = set_regions,
|
||||
|
|
Loading…
Reference in New Issue