split lines on enter

This commit is contained in:
Kartik K. Agaram 2022-05-17 22:05:46 -07:00
parent a787ef1716
commit 6c031fc1d0
1 changed files with 7 additions and 3 deletions

View File

@ -267,9 +267,13 @@ function keychord_pressed(chord)
-- Don't handle any keys here that would trigger love.textinput above. -- Don't handle any keys here that would trigger love.textinput above.
-- shortcuts for text -- shortcuts for text
if chord == 'return' then if chord == 'return' then
table.insert(Lines, Cursor_line+1, {mode='text', data=''}) local byte_offset = utf8.offset(Lines[Cursor_line].data, Cursor_pos)
Cursor_line = Cursor_line+1 if byte_offset then
Cursor_pos = 1 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 elseif chord == 'left' then
if Cursor_pos > 1 then if Cursor_pos > 1 then
Cursor_pos = Cursor_pos-1 Cursor_pos = Cursor_pos-1