about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-17 22:05:46 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-17 22:05:46 -0700
commit6c031fc1d0affdc41bd25ed5d8f6dbff399a3113 (patch)
treef9b10c8f70d670cd178019d16fbfb86fc1427448
parenta787ef171672351bff76797d42376bc863dbb899 (diff)
downloadlines.love-6c031fc1d0affdc41bd25ed5d8f6dbff399a3113.tar.gz
split lines on enter
-rw-r--r--main.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/main.lua b/main.lua
index cb4858b..93a97a9 100644
--- a/main.lua
+++ b/main.lua
@@ -267,9 +267,13 @@ function keychord_pressed(chord)
   -- Don't handle any keys here that would trigger love.textinput above.
   -- shortcuts for text
   if chord == 'return' then
-    table.insert(Lines, Cursor_line+1, {mode='text', data=''})
-    Cursor_line = Cursor_line+1
-    Cursor_pos = 1
+    local byte_offset = utf8.offset(Lines[Cursor_line].data, Cursor_pos)
+    if byte_offset then
+      table.insert(Lines, Cursor_line+1, {mode='text', data=string.sub(Lines[Cursor_line].data, byte_offset)})
+      Lines[Cursor_line].data = string.sub(Lines[Cursor_line].data, 1, byte_offset)
+      Cursor_line = Cursor_line+1
+      Cursor_pos = 1
+    end
   elseif chord == 'left' then
     if Cursor_pos > 1 then
       Cursor_pos = Cursor_pos-1