diff --git a/docs/Lua API.rst b/docs/Lua API.rst index d1dbc2856..30dc65744 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -3880,6 +3880,7 @@ Attributes: If it returns false, the character is ignored. :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_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_sep: If specified, will be used to customize how the activation key is displayed. See ``token.key_sep`` in the ``Label`` documentation below. diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index fcf6d4733..da5e2c37e 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -184,6 +184,7 @@ EditField.ATTRS{ on_char = DEFAULT_NIL, on_change = DEFAULT_NIL, on_submit = DEFAULT_NIL, + on_submit2 = DEFAULT_NIL, key = DEFAULT_NIL, key_sep = DEFAULT_NIL, frame = {h=1}, @@ -257,6 +258,17 @@ function EditField:onInput(keys) return not not self.key 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 local old = self.text if keys._STRING == 0 then