about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-03-26 07:19:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-03-26 07:19:27 -0700
commit7f433753b6f84e1107a2c3298ade3b309c493795 (patch)
treed1a5fc23a3de9219e2f3dd7629994c812bcb2149
parent57ed70d9125a45c819302c23445732b1acc14e8f (diff)
downloadtext.love-7f433753b6f84e1107a2c3298ade3b309c493795.tar.gz
bugfix
scenario: open a file starting with a drawing
After this commit the program doesn't crash.

  Error: [string "edit.lua"]:127: attempt to get length of field 'data' (a nil value)
  stack traceback:
    [love "boot.lua"]:345: in function '__len'
    [string "edit.lua"]:127: in function 'invalid1'
    [string "edit.lua"]:116: in function 'check_locs'
    [string "run.lua"]:35: in function 'initialize'
    main.lua:96: in function 'initialize'
    [string "app.lua"]:144: in function 'run_tests_and_initialize'
    [string "app.lua"]:16: in function <[string "app.lua"]:13>
    [C]: in function 'xpcall'
    [love "boot.lua"]:361: in function <[love "boot.lua"]:348>
    [C]: in function 'xpcall'
-rw-r--r--edit.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/edit.lua b/edit.lua
index 2b405a7..c05a2e5 100644
--- a/edit.lua
+++ b/edit.lua
@@ -122,8 +122,10 @@ function edit.check_locs(State)
 end
 
 function edit.invalid1(State, loc1)
-  return loc1.line > #State.lines
-      or loc1.pos > #State.lines[loc1.line].data
+  if loc1.line > #State.lines then return true end
+  local l = State.lines[loc1.line]
+  if l.mode ~= 'text' then return false end  -- pos is irrelevant to validity for a drawing line
+  return loc1.pos > #State.lines[loc1.line].data
 end
 
 function edit.cursor_on_text(State)