diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-16 20:26:27 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-16 20:26:27 -0700 |
commit | 63df6d04e00877acd135de710c1118306554945c (patch) | |
tree | 71f6fa063adb149cebb870601af99276b0772f64 | |
parent | ad17f4b9e47f54065402cd4a5042225db53c4ad2 (diff) | |
download | lines.love-63df6d04e00877acd135de710c1118306554945c.tar.gz |
up/down cursor movement
-rw-r--r-- | main.lua | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/main.lua b/main.lua index 32681d4..263e96e 100644 --- a/main.lua +++ b/main.lua @@ -150,18 +150,19 @@ function love.draw() end end end ---? print(#line.points) draw_pending_shape(16,line.y, line) else love.graphics.setColor(0,0,0) love.graphics.draw(text, 25,y, 0, 1.5) + if i == cursor_line then + -- cursor + love.graphics.setColor(0,0,0) + local line_before_cursor = lines[cursor_line]:sub(1, cursor_pos-1) + local text_before_cursor = love.graphics.newText(love.graphics.getFont(), line_before_cursor) + love.graphics.print('_', 25+text_before_cursor:getWidth()*1.5, y+6) -- drop the cursor down a bit to account for the increased font size + end end end - -- cursor - love.graphics.setColor(0,0,0) - local line_before_cursor = lines[cursor_line]:sub(1, cursor_pos-1) - local text_before_cursor = love.graphics.newText(love.graphics.getFont(), line_before_cursor) - love.graphics.print('_', 25+text_before_cursor:getWidth()*1.5, y+6) -- drop the cursor down a bit to account for the increased font size end function love.update(dt) @@ -509,7 +510,9 @@ end function keychord_pressed(chord) -- Don't handle any keys here that would trigger love.textinput above. if chord == 'return' then - table.insert(lines, '') + table.insert(lines, cursor_line+1, '') + cursor_line = cursor_line+1 + cursor_pos = 1 elseif chord == 'backspace' then if #lines > 1 and lines[#lines] == '' then table.remove(lines) @@ -537,6 +540,20 @@ function keychord_pressed(chord) if cursor_pos <= #lines[cursor_line] then cursor_pos = cursor_pos + 1 end + elseif chord == 'up' then + if cursor_line > 1 then + cursor_line = cursor_line-1 + if cursor_pos > #lines[cursor_line] then + cursor_pos = #lines[cursor_line]+1 + end + end + elseif chord == 'down' then + if cursor_line < #lines then + cursor_line = cursor_line+1 + if cursor_pos > #lines[cursor_line] then + cursor_pos = #lines[cursor_line]+1 + end + end elseif chord == 'delete' then if cursor_pos <= #lines[cursor_line] then local byte_start = utf8.offset(lines[cursor_line], cursor_pos) |