From 6c031fc1d0affdc41bd25ed5d8f6dbff399a3113 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 17 May 2022 22:05:46 -0700 Subject: split lines on enter --- main.lua | 10 +++++++--- 1 file 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 -- cgit 1.4.1-2-gfad0