about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--source.lua10
-rw-r--r--source_file.lua36
2 files changed, 44 insertions, 2 deletions
diff --git a/source.lua b/source.lua
index c582953..dbf1640 100644
--- a/source.lua
+++ b/source.lua
@@ -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
diff --git a/source_file.lua b/source_file.lua
index 8dd8832..54624b9 100644
--- a/source_file.lua
+++ b/source_file.lua
@@ -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