diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-09-15 08:46:36 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-09-15 08:46:36 -0700 |
commit | 0a12e4c733a2483eef840fb82aec4f4f6ec68b3c (patch) | |
tree | c0c160c9135458c1580d9c43d70316325eafc1d0 | |
parent | 0e20565e17cd9f1580aa2451de8b16b863ae0382 (diff) | |
download | lines.love-0a12e4c733a2483eef840fb82aec4f4f6ec68b3c.tar.gz |
change a helper slightly
-rw-r--r-- | edit.lua | 18 | ||||
-rw-r--r-- | source_edit.lua | 18 |
2 files changed, 22 insertions, 14 deletions
diff --git a/edit.lua b/edit.lua index 7c5e4e0..1ac2bd1 100644 --- a/edit.lua +++ b/edit.lua @@ -113,7 +113,7 @@ function edit.check_locs(State) or not edit.cursor_on_text(State) or not Text.le1(State.screen_top1, State.cursor1) then State.screen_top1 = {line=1, pos=1} - edit.put_cursor_on_first_text_line(State) + edit.put_cursor_on_next_text_line(State) end end @@ -139,12 +139,16 @@ function edit.cursor_on_text(State) and State.lines[State.cursor1.line].mode == 'text' end -function edit.put_cursor_on_first_text_line(State) - for i,line in ipairs(State.lines) do - if line.mode == 'text' then - State.cursor1 = {line=i, pos=1} - break - end +function edit.put_cursor_on_next_text_line(State) + while true do + if State.cursor1.line >= #State.lines then + break + end + if State.lines[State.cursor1.line].mode == 'text' then + break + end + State.cursor1.line = State.cursor1.line+1 + State.cursor1.pos = 1 end end diff --git a/source_edit.lua b/source_edit.lua index 78c7f4d..f949aa5 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -115,7 +115,7 @@ function edit.check_locs(State) or not edit.cursor_on_text(State) or not Text.le1(State.screen_top1, State.cursor1) then State.screen_top1 = {line=1, pos=1} - edit.put_cursor_on_first_text_line(State) + edit.put_cursor_on_next_text_line(State) end end @@ -131,12 +131,16 @@ function edit.cursor_on_text(State) and State.lines[State.cursor1.line].mode == 'text' end -function edit.put_cursor_on_first_text_line(State) - for i,line in ipairs(State.lines) do - if line.mode == 'text' then - State.cursor1 = {line=i, pos=1} - break - end +function edit.put_cursor_on_next_text_line(State) + while true do + if State.cursor1.line >= #State.lines then + break + end + if State.lines[State.cursor1.line].mode == 'text' then + break + end + State.cursor1.line = State.cursor1.line+1 + State.cursor1.pos = 1 end end |