about summary refs log tree commit diff stats
path: root/source.lua
diff options
context:
space:
mode:
Diffstat (limited to 'source.lua')
-rw-r--r--source.lua60
1 files changed, 37 insertions, 23 deletions
diff --git a/source.lua b/source.lua
index c763994..4047f38 100644
--- a/source.lua
+++ b/source.lua
@@ -45,6 +45,7 @@ function source.initialize_globals()
     },
     index = 1,
     filter = '',
+    cursors = {},  -- filename to cursor1, screen_top1
   }
   File_navigation.candidates = File_navigation.all_candidates  -- modified with filter
 
@@ -71,7 +72,7 @@ function source.initialize()
     source.initialize_default_settings()
   end
 
-  source.initialize_edit_side{'run.lua'}
+  source.initialize_edit_side()
   source.initialize_log_browser_side()
 
   Menu_status_bar_height = 5 + Editor_state.line_height + 5
@@ -82,20 +83,15 @@ end
 
 -- environment for a mutable file of bifolded text
 -- TODO: some initialization is also happening in load_settings/initialize_default_settings. Clean that up.
-function source.initialize_edit_side(arg)
-  if #arg > 0 then
-    Editor_state.filename = arg[1]
-    load_from_disk(Editor_state)
-    Text.redraw_all(Editor_state)
+function source.initialize_edit_side()
+  load_from_disk(Editor_state)
+  Text.redraw_all(Editor_state)
+  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}
-  else
-    load_from_disk(Editor_state)
-    Text.redraw_all(Editor_state)
-  end
-
-  if #arg > 1 then
-    print('ignoring commandline args after '..arg[1])
   end
 
   -- We currently start out with side B collapsed.
@@ -138,8 +134,16 @@ 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.screen_top1 = settings.screen_top
-  Editor_state.cursor1 = settings.cursor
+  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
+    Editor_state.cursor1 = File_navigation.cursors[Editor_state.filename].cursor1
+  else
+    -- migrate old settings
+    Editor_state.screen_top1 = {line=1, pos=1}
+    Editor_state.cursor1 = {line=1, pos=1}
+  end
 end
 
 function source.set_window_position_from_settings(settings)
@@ -153,6 +157,7 @@ function source.initialize_default_settings()
   local em = App.newText(love.graphics.getFont(), 'm')
   source.initialize_window_geometry(App.width(em))
   Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)
+  Editor_state.filename = 'run.lua'
   Editor_state.font_height = font_height
   Editor_state.line_height = math.floor(font_height*1.3)
   Editor_state.em = em
@@ -214,12 +219,19 @@ function source.switch_to_file(filename)
   if Editor_state.next_save then
     save_to_disk(Editor_state)
   end
+  -- save cursor position
+  File_navigation.cursors[Editor_state.filename] = {cursor1=Editor_state.cursor1, screen_top1=Editor_state.screen_top1}
   -- clear the slate for the new file
   Editor_state.filename = filename
   load_from_disk(Editor_state)
   Text.redraw_all(Editor_state)
-  Editor_state.screen_top1 = {line=1, pos=1}
-  Editor_state.cursor1 = {line=1, pos=1}
+  if File_navigation.cursors[filename] then
+    Editor_state.screen_top1 = File_navigation.cursors[filename].screen_top1
+    Editor_state.cursor1 = File_navigation.cursors[filename].cursor1
+  else
+    Editor_state.screen_top1 = {line=1, pos=1}
+    Editor_state.cursor1 = {line=1, pos=1}
+  end
 end
 
 function source.draw()
@@ -260,17 +272,14 @@ function source.settings()
 --?     print('reading source window position')
     Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position()
   end
-  local filename = Editor_state.filename
-  if is_relative_path(filename) then
-    filename = love.filesystem.getWorkingDirectory()..'/'..filename  -- '/' should work even on Windows
-  end
 --?   print('saving source settings', Settings.source.x, Settings.source.y, Settings.source.displayindex)
+  File_navigation.cursors[Editor_state.filename] = {cursor1=Editor_state.cursor1, screen_top1=Editor_state.screen_top1}
   return {
     x=Settings.source.x, y=Settings.source.y, displayindex=Settings.source.displayindex,
     width=App.screen.width, height=App.screen.height,
     font_height=Editor_state.font_height,
-    filename=filename,
-    screen_top=Editor_state.screen_top1, cursor=Editor_state.cursor1,
+    filename=Editor_state.filename,
+    cursors=File_navigation.cursors,
     show_log_browser_side=Show_log_browser_side,
     focus=Focus,
   }
@@ -281,6 +290,11 @@ function source.mouse_pressed(x,y, mouse_button)
 --?   print('mouse click', x, y)
 --?   print(Editor_state.left, Editor_state.right)
 --?   print(Log_browser_state.left, Log_browser_state.right)
+  if Show_file_navigator and y < Menu_status_bar_height + File_navigation.num_lines * Editor_state.line_height then
+    -- send click to buttons
+    edit.mouse_pressed(Editor_state, x,y, mouse_button)
+    return
+  end
   if x < Editor_state.right + Margin_right then
 --?     print('click on edit side')
     if Focus ~= 'edit' then