[input] Invoke onChange() on text change.

master
Lorenzo Cogotti 2 years ago
parent 4d2083d143
commit b06d56b945

@ -85,6 +85,8 @@ function Input:textinput(text)
self.text = table.concat {a, text, b}
self.cursor = self.cursor + utf8.len(text)
self:onChange(self.text)
end
end
@ -100,21 +102,22 @@ function Input:keypressed(key, code, isrepeat)
end
if self.candidate.length == 0 then
if key == 'backspace' then
if key == 'backspace' and self.cursor > 1 then
local a,b = split(self.text, self.cursor)
self.text = table.concat { split(a, utf8.len(a)), b }
self.cursor = math.max(1, self.cursor-1)
self.cursor = self.cursor-1
elseif key == 'delete' then
self:onChange(self.text)
elseif key == 'delete' and self.cursor ~= utf8.len(self.text)+1 then
local a,b = split(self.text, self.cursor)
local _,b = split(b, 2)
self.text = table.concat { a, b }
self:onChange(self.text)
elseif key == 'left' then
self.cursor = math.max(0, self.cursor-1)
self.cursor = math.max(1, self.cursor-1)
elseif key == 'right' then
self.cursor = math.min(utf8.len(self.text)+1, self.cursor+1)
end

Loading…
Cancel
Save