allow EditFields to ignore specified keys

like "+" and "-", so you can use them as hotkeys in the parent view
develop
myk002 2022-08-29 11:40:56 -07:00 committed by Myk
parent 2b7a153509
commit 074a6ec5cd
3 changed files with 15 additions and 0 deletions

@ -3986,6 +3986,9 @@ Attributes:
widgets while it has focus. You can set this to ``true``, for example,
if you don't want a ``List`` widget to react to arrow keys while the
user is editing.
:ignore_keys: If specified, must be a list of key names that the edit field
should ignore. This is useful if you have plain string characters
that you want to use as hotkeys (like ``+``).
An ``EditField`` will only read and process text input if it has keyboard focus.
It will automatically acquire keyboard focus when it is added as a subview to
@ -4311,6 +4314,7 @@ supports:
:edit_pen: If specified, used instead of ``cursor_pen`` for the edit field.
:edit_below: If true, the edit field is placed below the list instead of above.
:edit_key: If specified, the edit field is disabled until this key is pressed.
:edit_ignore_keys: If specified, must be a list of key names that the filter edit field should ignore.
:not_found_label: Specifies the text of the label shown when no items match the filter.
The list choices may include the following attributes:

@ -73,6 +73,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``tile-material``: fix the order of declarations. The ``GetTileMat`` function now returns the material as intended (always returned nil before). Also changed the license info, with permission of the original author.
- ``widgets.EditField``: new ``onsubmit2`` callback attribute is called when the user hits Shift-Enter.
- ``widgets.EditField``: new function: ``setCursor(position)`` sets the input cursor.
- ``widgets.EditField``: new attribute: ``ignore_keys`` lets you ignore specified characters if you want to use them as hotkeys
- ``widgets.FilteredList``: new attribute: ``edit_ignore_keys`` gets passed to the filter EditField as ``ignore_keys``
- ``widgets.Label``: ``scroll`` function now interprets the keywords ``+page``, ``-page``, ``+halfpage``, and ``-halfpage`` in addition to simple positive and negative numbers.
- ``widgets.HotkeyLabel``: clicking on the widget will now call ``on_activate()``.
- ``widgets.CycleHotkeyLabel``: clicking on the widget will now cycle the options and trigger ``on_change()``. This also applies to the ``ToggleHotkeyLabel`` subclass.

@ -188,6 +188,7 @@ EditField.ATTRS{
key = DEFAULT_NIL,
key_sep = DEFAULT_NIL,
modal = false,
ignore_keys = DEFAULT_NIL,
}
function EditField:preinit(init_table)
@ -270,6 +271,12 @@ function EditField:onInput(keys)
return self:inputToSubviews(keys)
end
if self.ignore_keys then
for _,ignore_key in ipairs(self.ignore_keys) do
if keys[ignore_key] then return false end
end
end
if self.key and keys.LEAVESCREEN then
local old = self.text
self:setText(self.saved_text)
@ -1099,6 +1106,7 @@ FilteredList = defclass(FilteredList, Widget)
FilteredList.ATTRS {
edit_below = false,
edit_key = DEFAULT_NIL,
edit_ignore_keys = DEFAULT_NIL,
}
function FilteredList:init(info)
@ -1108,6 +1116,7 @@ function FilteredList:init(info)
on_change = self:callback('onFilterChange'),
on_char = self:callback('onFilterChar'),
key = self.edit_key,
ignore_keys = self.edit_ignore_keys,
}
self.list = List{
frame = { t = 2 },