ensure changing text fires the on_change event

develop
Myk Taylor 2023-07-02 19:27:07 -07:00
parent 175c249d29
commit 07e8edcdca
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 4 additions and 7 deletions

@ -640,8 +640,12 @@ function EditField:setCursor(cursor)
end end
function EditField:setText(text, cursor) function EditField:setText(text, cursor)
local old = self.text
self.text = text self.text = text
self:setCursor(cursor) self:setCursor(cursor)
if self.on_change and text ~= old then
self.on_change(self.text, old)
end
end end
function EditField:postUpdateLayout() function EditField:postUpdateLayout()
@ -699,11 +703,7 @@ function EditField:onInput(keys)
end end
if self.key and (keys.LEAVESCREEN or keys._MOUSE_R_DOWN) then if self.key and (keys.LEAVESCREEN or keys._MOUSE_R_DOWN) then
local old = self.text
self:setText(self.saved_text) self:setText(self.saved_text)
if self.on_change and old ~= self.saved_text then
self.on_change(self.text, old)
end
self:setFocus(false) self:setFocus(false)
return true return true
end end
@ -747,9 +747,6 @@ function EditField:onInput(keys)
return self.modal return self.modal
end end
end end
if self.on_change and self.text ~= old then
self.on_change(self.text, old)
end
return true return true
elseif keys.KEYBOARD_CURSOR_LEFT then elseif keys.KEYBOARD_CURSOR_LEFT then
self:setCursor(self.cursor - 1) self:setCursor(self.cursor - 1)