about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-16 20:26:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-16 20:26:27 -0700
commit63df6d04e00877acd135de710c1118306554945c (patch)
tree71f6fa063adb149cebb870601af99276b0772f64
parentad17f4b9e47f54065402cd4a5042225db53c4ad2 (diff)
downloadlines.love-63df6d04e00877acd135de710c1118306554945c.tar.gz
up/down cursor movement
-rw-r--r--main.lua31
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)
p;id=1156971774b307bec29fab34a523eb39a7904174'>^
8b095f80 ^

8b095f80 ^

8b095f80 ^



bd5d3936 ^

639922e8 ^
8b095f80 ^

d8509b41 ^
8b095f80 ^

8b095f80 ^
8b095f80 ^
6c96a437 ^
8b095f80 ^

6c96a437 ^
78c50205 ^
8b095f80 ^

d559f68b ^
3c4c9c08 ^
8b095f80 ^









8b095f80 ^
2badd89a ^

6c96a437 ^
2badd89a ^
6c96a437 ^
2badd89a ^

6c96a437 ^
2badd89a ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76