diff options
-rw-r--r-- | edit.lua | 11 | ||||
-rw-r--r-- | main.lua | 16 |
2 files changed, 13 insertions, 14 deletions
diff --git a/edit.lua b/edit.lua index b1a315d..1b39dbb 100644 --- a/edit.lua +++ b/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) diff --git a/main.lua b/main.lua index 6c5dc9c..85bfb35 100644 --- a/main.lua +++ b/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) |