diff options
author | Matthias Richter <matthias.richter@iosb.fraunhofer.de> | 2013-12-11 15:19:04 +0100 |
---|---|---|
committer | Matthias Richter <matthias.richter@iosb.fraunhofer.de> | 2013-12-11 15:25:06 +0100 |
commit | 66a089a07f4d24557cb8e06f78eefb07a344ea32 (patch) | |
tree | 9e9fbaa80393cb50d5fa05b94098a1a99717d5ec /input.lua | |
parent | ffd187dc177f4a15fa2e87579b9cbabee38b8245 (diff) | |
download | Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.gz Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.bz2 Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.xz Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.zip |
Fix bug in input.lua, make 0.9-ready, add utf8 editing
1) [input.lua] Pressing backspace while the cursor was at the beggining
of the text removed the first character. Fixed thanks to riidom.
2) [LÖVE 0.9] Use setLine(Width|Style) instead of setLine. Split
keyboard.pressed() into keyboard.pressed() and keyboard.textinput().
(see readme)
3) [utf8.lua] Add support for UTF-8 text editing. May still fail
spectacurlarly with invalid UTF-8 strings.
Diffstat (limited to 'input.lua')
-rw-r--r-- | input.lua | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -29,6 +29,7 @@ local core = require(BASE .. 'core') local group = require(BASE .. 'group') local mouse = require(BASE .. 'mouse') local keyboard = require(BASE .. 'keyboard') +local utf8 = require(BASE .. 'utf8') -- {info = {text = "", cursor = text:len()}, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} return function(w) @@ -45,11 +46,13 @@ return function(w) if not keyboard.hasFocus(id) then --[[nothing]] -- editing - elseif keyboard.key == 'backspace' then - w.info.text = w.info.text:sub(1,w.info.cursor-1) .. w.info.text:sub(w.info.cursor+1) + elseif keyboard.key == 'backspace' and w.info.cursor > 0 then w.info.cursor = math.max(0, w.info.cursor-1) + local left, right = utf8.split(w.info.text, w.info.cursor) + w.info.text = left .. utf8.sub(right, 2) elseif keyboard.key == 'delete' then - w.info.text = w.info.text:sub(1,w.info.cursor) .. w.info.text:sub(w.info.cursor+2) + local left, right = utf8.split(w.info.text, w.info.cursor) + w.info.text = left .. utf8.sub(right, 2) w.info.cursor = math.min(w.info.text:len(), w.info.cursor) -- movement elseif keyboard.key == 'left' then @@ -64,10 +67,9 @@ return function(w) elseif keyboard.key == 'return' then keyboard.clearFocus() keyboard.pressed('', -1) - elseif keyboard.code >= 32 and keyboard.code < 127 then - local left = w.info.text:sub(1,w.info.cursor) - local right = w.info.text:sub(w.info.cursor+1) - w.info.text = table.concat{left, string.char(keyboard.code), right} + elseif keyboard.str then + local left, right = utf8.split(w.info.text, w.info.cursor) + w.info.text = left .. keyboard.str .. right w.info.cursor = w.info.cursor + 1 end |