diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-02 08:28:33 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-02 08:28:33 -0700 |
commit | 02307268133e602de0a3c0907e62ee7ef0cc4461 (patch) | |
tree | fde99472ec91a42caf7eb47b89f06dae8660eada /main.lua | |
parent | 4aa2003c94e8cdadde3d353a8cbc631c3a92833d (diff) | |
download | lines.love-02307268133e602de0a3c0907e62ee7ef0cc4461.tar.gz |
backspace
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/main.lua b/main.lua index e9bccf5..df75189 100644 --- a/main.lua +++ b/main.lua @@ -1,4 +1,5 @@ require 'keychord' +local utf8 = require 'utf8' lines = {} width, height, flags = 0, 0, nil @@ -35,6 +36,15 @@ function keychord_pressed(chord) -- Don't handle any keys here that would trigger love.textinput above. if chord == 'return' then table.insert(lines, '') + elseif chord == 'backspace' then + if #lines > 1 and lines[#lines] == '' then + table.remove(lines) + else + local byteoffset = utf8.offset(lines[#lines], -1) + if byteoffset then + lines[#lines] = string.sub(lines[#lines], 1, byteoffset-1) + end + end elseif chord == 'C-r' then lines[#lines+1] = eval(lines[#lines])[1] lines[#lines+1] = '' |