From b06d56b9453f81d96b804697b004af7354126f85 Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Sun, 2 Oct 2022 17:54:00 +0200 Subject: [PATCH] [input] Invoke onChange() on text change. --- input.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/input.lua b/input.lua index b72768b..7cc0a26 100644 --- a/input.lua +++ b/input.lua @@ -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