extract method
This commit is contained in:
parent
b7a67ab1e9
commit
6f74f95a46
11
edit.lua
11
edit.lua
|
@ -118,6 +118,17 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
|
|||
return result
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function edit.draw(State)
|
||||
App.color(Text_color)
|
||||
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
|
||||
|
|
16
main.lua
16
main.lua
|
@ -42,23 +42,11 @@ function App.initialize(arg)
|
|||
Text.redraw_all(Editor_state)
|
||||
Editor_state.screen_top1 = {line=1, pos=1}
|
||||
Editor_state.cursor1 = {line=1, pos=1}
|
||||
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)
|
||||
else
|
||||
Editor_state.lines = load_from_disk(Editor_state.filename)
|
||||
Text.redraw_all(Editor_state)
|
||||
if Editor_state.cursor1.line > #Editor_state.lines or Editor_state.lines[Editor_state.cursor1.line].mode ~= 'text' then
|
||||
for i,line in ipairs(Editor_state.lines) do
|
||||
if line.mode == 'text' then
|
||||
Editor_state.cursor1.line = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
edit.fixup_cursor(Editor_state)
|
||||
end
|
||||
love.window.setTitle('lines.love - '..Editor_state.filename)
|
||||
|
||||
|
|
Loading…
Reference in New Issue