From 7f433753b6f84e1107a2c3298ade3b309c493795 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 26 Mar 2023 07:19:27 -0700 Subject: 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' --- edit.lua | 6 ++++-- 1 file 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) -- cgit 1.4.1-2-gfad0