support submit2 for EditFields

develop
myk002 2022-07-15 13:46:01 -07:00 committed by Myk
parent 214dd3c579
commit 43b1abcdcf
2 changed files with 13 additions and 0 deletions

@ -3880,6 +3880,7 @@ Attributes:
If it returns false, the character is ignored. If it returns false, the character is ignored.
:on_change: Change notification callback; used as ``on_change(new_text,old_text)``. :on_change: Change notification callback; used as ``on_change(new_text,old_text)``.
:on_submit: Enter key callback; if set the field will handle the key and call ``on_submit(text)``. :on_submit: Enter key callback; if set the field will handle the key and call ``on_submit(text)``.
:on_submit2: Shift-Enter key callback; if set the field will handle the key and call ``on_submit2(text)``.
:key: If specified, the field is disabled until this key is pressed. Must be given as a string. :key: If specified, the field is disabled until this key is pressed. Must be given as a string.
:key_sep: If specified, will be used to customize how the activation key is :key_sep: If specified, will be used to customize how the activation key is
displayed. See ``token.key_sep`` in the ``Label`` documentation below. displayed. See ``token.key_sep`` in the ``Label`` documentation below.

@ -184,6 +184,7 @@ EditField.ATTRS{
on_char = DEFAULT_NIL, on_char = DEFAULT_NIL,
on_change = DEFAULT_NIL, on_change = DEFAULT_NIL,
on_submit = DEFAULT_NIL, on_submit = DEFAULT_NIL,
on_submit2 = DEFAULT_NIL,
key = DEFAULT_NIL, key = DEFAULT_NIL,
key_sep = DEFAULT_NIL, key_sep = DEFAULT_NIL,
frame = {h=1}, frame = {h=1},
@ -257,6 +258,17 @@ function EditField:onInput(keys)
return not not self.key return not not self.key
end end
if keys.SEC_SELECT then
if self.key then
self:setFocus(false)
end
if self.on_submit2 then
self.on_submit2(self.text)
return true
end
return not not self.key
end
if keys._STRING then if keys._STRING then
local old = self.text local old = self.text
if keys._STRING == 0 then if keys._STRING == 0 then