Add previous find and replace in session

This commit is contained in:
Francesco Abbate 2021-09-07 22:31:36 +02:00 committed by Francesco
parent 403b7f6fb6
commit 04250a206a
1 changed files with 10 additions and 11 deletions

View File

@ -17,10 +17,7 @@ local core = {}
local function load_session() local function load_session()
local ok, t = pcall(dofile, USERDIR .. "/session.lua") local ok, t = pcall(dofile, USERDIR .. "/session.lua")
if ok and t then return ok and t or {}
return t.recents, t.window, t.window_mode
end
return {}
end end
@ -30,6 +27,8 @@ local function save_session()
fp:write("return {recents=", common.serialize(core.recent_projects), fp:write("return {recents=", common.serialize(core.recent_projects),
", window=", common.serialize(table.pack(system.get_window_size())), ", window=", common.serialize(table.pack(system.get_window_size())),
", window_mode=", common.serialize(system.get_window_mode()), ", window_mode=", common.serialize(system.get_window_mode()),
", previous_find=", common.serialize(core.previous_find),
", previous_replace=", common.serialize(core.previous_replace),
"}\n") "}\n")
fp:close() fp:close()
end end
@ -435,13 +434,15 @@ function core.init()
end end
do do
local recent_projects, window_position, window_mode = load_session() local session = load_session()
if window_mode == "normal" then if session.window_mode == "normal" then
system.set_window_size(table.unpack(window_position)) system.set_window_size(table.unpack(session.window))
elseif window_mode == "maximized" then elseif session.window_mode == "maximized" then
system.set_window_mode("maximized") system.set_window_mode("maximized")
end end
core.recent_projects = recent_projects or {} core.recent_projects = session.recents or {}
core.previous_find = session.previous_find or {}
core.previous_replace = session.previous_replace or {}
end end
local project_dir = core.recent_projects[1] or "." local project_dir = core.recent_projects[1] or "."
@ -496,8 +497,6 @@ function core.init()
core.redraw = true core.redraw = true
core.visited_files = {} core.visited_files = {}
core.previous_find = {}
core.previous_replace = {}
core.restart_request = false core.restart_request = false
core.quit_request = false core.quit_request = false
core.replacements = whitespace_replacements() core.replacements = whitespace_replacements()