about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-18 20:22:57 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-18 20:22:57 -0700
commitb63a33dd069c88fabdba60690e4c01e8a210d0be (patch)
treeb41bdc48042cb13faf4f510a133ff12464d6718c
parentec410d5223fc7a30f69571d5a7e0bbffc26ede6b (diff)
downloadtext.love-b63a33dd069c88fabdba60690e4c01e8a210d0be.tar.gz
handle tab characters
-rw-r--r--text.lua9
1 files changed, 8 insertions, 1 deletions
diff --git a/text.lua b/text.lua
index af205b6..134d7c1 100644
--- a/text.lua
+++ b/text.lua
@@ -16,6 +16,11 @@ end
 function love.textinput(t)
   if love.mouse.isDown('1') then return end
   if Lines[Cursor_line].mode == 'drawing' then return end
+  Text.insert_at_cursor(t)
+  save_to_disk(Lines, Filename)
+end
+
+function Text.insert_at_cursor(t)
   local byte_offset
   if Cursor_pos > 1 then
     byte_offset = utf8.offset(Lines[Cursor_line].data, Cursor_pos-1)
@@ -24,7 +29,6 @@ function love.textinput(t)
   end
   Lines[Cursor_line].data = string.sub(Lines[Cursor_line].data, 1, byte_offset)..t..string.sub(Lines[Cursor_line].data, byte_offset+1)
   Cursor_pos = Cursor_pos+1
-  save_to_disk(Lines, Filename)
 end
 
 -- Don't handle any keys here that would trigger love.textinput above.
@@ -36,6 +40,9 @@ function Text.keychord_pressed(chord)
     Cursor_line = Cursor_line+1
     Cursor_pos = 1
     save_to_disk(Lines, Filename)
+  elseif chord == 'tab' then
+    Text.insert_at_cursor('\t')
+    save_to_disk(Lines, Filename)
   elseif chord == 'left' then
     assert(Lines[Cursor_line].mode == 'text')
     if Cursor_pos > 1 then