about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--edit.lua10
-rw-r--r--main.lua11
2 files changed, 8 insertions, 13 deletions
diff --git a/edit.lua b/edit.lua
index efc6f71..ccf675b 100644
--- a/edit.lua
+++ b/edit.lua
@@ -119,12 +119,10 @@ function edit.initialize_state(top, left, right, font_height, line_height)  -- c
 end  -- App.initialize_state
 
 function edit.fixup_cursor(State)
-  if State.cursor1.line > #State.lines or State.lines[State.cursor1.line].mode ~= 'text' then
-    for i,line in ipairs(State.lines) do
-      if line.mode == 'text' then
-        State.cursor1.line = i
-        break
-      end
+  for i,line in ipairs(State.lines) do
+    if line.mode == 'text' then
+      State.cursor1.line = i
+      break
     end
   end
 end
diff --git a/main.lua b/main.lua
index 5f920ee..de75045 100644
--- a/main.lua
+++ b/main.lua
@@ -47,7 +47,9 @@ function App.initialize(arg)
   else
     load_from_disk(Editor_state)
     Text.redraw_all(Editor_state)
-    edit.fixup_cursor(Editor_state)
+    if Editor_state.cursor1.line > #Editor_state.lines or Editor_state.lines[Editor_state.cursor1.line].mode ~= 'text' then
+      edit.fixup_cursor(Editor_state)
+    end
   end
   love.window.setTitle('lines.love - '..Editor_state.filename)
 
@@ -125,12 +127,7 @@ function App.filedropped(file)
   file:open('r')
   Editor_state.lines = load_from_file(file)
   file:close()
-  for i,line in ipairs(Editor_state.lines) do
-    if line.mode == 'text' then
-      Editor_state.cursor1.line = i
-      break
-    end
-  end
+  edit.fixup_cursor(Editor_state)
   love.window.setTitle('lines.love - '..Editor_state.filename)
 end