diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2024-10-29 18:15:16 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2024-10-29 18:15:16 -0700 |
commit | 7e5653c8d39f6cc9393ed2cefb55b3de9640d3d3 (patch) | |
tree | 291fa2dd0f27df5d2a5de3b9391ee01bb42d7710 /edit.lua | |
parent | 549423b01891b2bebfc869802f71e01327b9553b (diff) | |
parent | 6975b8b7210296da1280a56c29f279eac39cdbda (diff) | |
download | view.love-7e5653c8d39f6cc9393ed2cefb55b3de9640d3d3.tar.gz |
Merge lines.love
Diffstat (limited to 'edit.lua')
-rw-r--r-- | edit.lua | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/edit.lua b/edit.lua index 4b7a2fc..3001bed 100644 --- a/edit.lua +++ b/edit.lua @@ -97,6 +97,28 @@ function edit.invalid_cursor1(State) return cursor1.pos > #State.lines[cursor1.line].data + 1 end +function edit.put_cursor_on_next_text_line_wrapping_around_if_necessary(State) + local line = State.cursor1.line + local max = #State.lines + for _ = 1, max-1 do + line = (line+1) % max + if State.lines[line].mode == 'text' then + State.cursor1.line = line + State.cursor1.pos = 1 + break + end + end +end + +function edit.put_cursor_on_next_loc_wrapping_around_if_necessary(State) + local cursor_line = State.lines[State.cursor1.line].data + if State.cursor1.pos <= utf8.len(cursor_line) then + State.cursor1.pos = State.cursor1.pos + 1 + else + edit.put_cursor_on_next_text_line_wrapping_around_if_necessary(State) + end +end + function edit.draw(State) love.graphics.setFont(State.font) App.color(Text_color) @@ -283,8 +305,10 @@ function edit.keychord_press(State, chord, key) State.screen_top = deepcopy(State.search_backup.screen_top) Text.search_next(State) elseif chord == 'down' then - State.cursor1.pos = State.cursor1.pos+1 - Text.search_next(State) + if #State.search_term > 0 then + edit.put_cursor_on_next_loc_wrapping_around_if_necessary(State) + Text.search_next(State) + end elseif chord == 'up' then Text.search_previous(State) end |