Interpret '4' & '6' as strings, not movement keys

develop
myk002 2022-08-19 22:40:53 -07:00
parent ade8177336
commit 8acda4d6c8
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 20 additions and 20 deletions

@ -304,6 +304,26 @@ function EditField:onInput(keys)
self:setCursor(self.start_pos + mouse_x)
return true
end
elseif keys._STRING then
local old = self.text
if keys._STRING == 0 then
-- handle backspace
local del_pos = self.cursor - 1
if del_pos > 0 then
self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1),
del_pos)
end
else
local cv = string.char(keys._STRING)
if not self.on_char or self.on_char(cv, old) then
self:setText(old:sub(1,self.cursor-1)..cv..old:sub(self.cursor),
self.cursor + 1)
end
end
if self.on_change and self.text ~= old then
self.on_change(self.text, old)
end
return true
elseif keys.CURSOR_LEFT then
self:setCursor(self.cursor - 1)
return true
@ -325,26 +345,6 @@ function EditField:onInput(keys)
elseif keys.A_CARE_MOVE_E then -- Alt-Right (end)
self:setCursor()
return true
elseif keys._STRING then
local old = self.text
if keys._STRING == 0 then
-- handle backspace
local del_pos = self.cursor - 1
if del_pos > 0 then
self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1),
del_pos)
end
else
local cv = string.char(keys._STRING)
if not self.on_char or self.on_char(cv, old) then
self:setText(old:sub(1,self.cursor-1)..cv..old:sub(self.cursor),
self.cursor + 1)
end
end
if self.on_change and self.text ~= old then
self.on_change(self.text, old)
end
return true
end
-- if we're modal, then unconditionally eat all the input