remove some duplication

This commit is contained in:
Kartik K. Agaram 2022-08-14 08:10:24 -07:00
parent 4d1e7f922d
commit 9459d91abc
2 changed files with 8 additions and 13 deletions

View File

@ -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

View File

@ -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