about summary refs log tree commit diff stats
path: root/source.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-09-19 00:10:12 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-09-19 00:10:12 -0700
commit76243382d77be1c0c4ec5fe712811c178730cb8e (patch)
treeb1e0b8558637cc7b2dc58cda1e652a5ad3246c50 /source.lua
parentaae35c7e046fe995f04f7b4938730dea83a29a5d (diff)
downloadlines.love-76243382d77be1c0c4ec5fe712811c178730cb8e.tar.gz
source: remember cursor position of multiple files
Diffstat (limited to 'source.lua')
-rw-r--r--source.lua16
1 files changed, 12 insertions, 4 deletions
diff --git a/source.lua b/source.lua
index e0f3918..bc35a49 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
 
@@ -214,12 +215,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()
@@ -261,13 +269,13 @@ function source.settings()
     Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position()
   end
 --?   print('saving source settings', Settings.source.x, Settings.source.y, Settings.source.displayindex)
-  print(Editor_state.filename)
+  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=Editor_state.filename,
-    screen_top=Editor_state.screen_top1, cursor=Editor_state.cursor1,
+    cursors=File_navigation.cursors,
     show_log_browser_side=Show_log_browser_side,
     focus=Focus,
   }