migrate old settings, attempt #3

This time we have to handle absolute filenames.
Now lines-polygon-experiment fork should merge successfully, at least.
This commit is contained in:
Kartik K. Agaram 2022-09-19 00:53:25 -07:00
parent 6ac45b75b9
commit d1d05fe5c9
2 changed files with 44 additions and 2 deletions

View File

@ -86,8 +86,13 @@ end
function source.initialize_edit_side()
load_from_disk(Editor_state)
Text.redraw_all(Editor_state)
Editor_state.screen_top1 = File_navigation.cursors[Editor_state.filename].screen_top1
Editor_state.cursor1 = File_navigation.cursors[Editor_state.filename].cursor1
if File_navigation.cursors[Editor_state.filename] then
Editor_state.screen_top1 = File_navigation.cursors[Editor_state.filename].screen_top1
Editor_state.cursor1 = File_navigation.cursors[Editor_state.filename].cursor1
else
Editor_state.screen_top1 = {line=1, pos=1}
Editor_state.cursor1 = {line=1, pos=1}
end
-- We currently start out with side B collapsed.
-- Other options:
@ -129,6 +134,7 @@ function source.load_settings()
end
Editor_state = edit.initialize_state(Margin_top, Margin_left, right, settings.font_height, math.floor(settings.font_height*1.3))
Editor_state.filename = settings.filename
Editor_state.filename = basename(Editor_state.filename) -- migrate settings that used full paths; we now support only relative paths within the app
if settings.cursors then
File_navigation.cursors = settings.cursors
Editor_state.screen_top1 = File_navigation.cursors[Editor_state.filename].screen_top1

View File

@ -216,3 +216,39 @@ end
function is_relative_path(path)
return not is_absolute_path(path)
end
function dirname(path)
local os_path_separator = package.config:sub(1,1)
if os_path_separator == '/' then
-- POSIX systems permit backslashes in filenames
return path:match('.*/') or './'
elseif os_path_separator == '\\' then
return path:match('.*[/\\]') or './'
else
error('What OS is this? LÖVE reports that the path separator is "'..os_path_separator..'"')
end
end
function test_dirname()
check_eq(dirname('a/b'), 'a/', 'F - test_dirname')
check_eq(dirname('x'), './', 'F - test_dirname/current')
end
function basename(path)
local os_path_separator = package.config:sub(1,1)
if os_path_separator == '/' then
-- POSIX systems permit backslashes in filenames
return string.gsub(path, ".*/(.*)", "%1")
elseif os_path_separator == '\\' then
return string.gsub(path, ".*[/\\](.*)", "%1")
else
error('What OS is this? LÖVE reports that the path separator is "'..os_path_separator..'"')
end
end
function empty(h)
for _,_ in pairs(h) do
return false
end
return true
end