Merge pull request #2837 from robob27/case-insensitive-filterlist

Add case_sensitive attr to FilteredList
develop
Myk 2023-02-08 11:18:31 -08:00 committed by GitHub
commit 201fec6873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

@ -57,6 +57,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Lua ## Lua
- `overlay`: overlay widgets can now specify focus paths for the viewscreens they attach to so they only appear in specific contexts. see `overlay-dev-guide` for details. - `overlay`: overlay widgets can now specify focus paths for the viewscreens they attach to so they only appear in specific contexts. see `overlay-dev-guide` for details.
- ``widgets.CycleHotkeyLabel``: Added ``key_back`` optional parameter to cycle backwards. - ``widgets.CycleHotkeyLabel``: Added ``key_back`` optional parameter to cycle backwards.
- ``widgets.FilteredList``: Added ``case_sensitive`` optional paramter to determine if filtering is case sensitive.
## Removed ## Removed

@ -4958,6 +4958,7 @@ construction that allows filtering the list by subwords of its items.
In addition to passing through all attributes supported by List, it In addition to passing through all attributes supported by List, it
supports: supports:
:case_sensitive: If true, matching is case sensitive. Defaults to true.
:edit_pen: If specified, used instead of ``cursor_pen`` for the edit field. :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_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_key: If specified, the edit field is disabled until this key is pressed.

@ -1868,6 +1868,7 @@ end
FilteredList = defclass(FilteredList, Widget) FilteredList = defclass(FilteredList, Widget)
FilteredList.ATTRS { FilteredList.ATTRS {
case_sensitive = true,
edit_below = false, edit_below = false,
edit_key = DEFAULT_NIL, edit_key = DEFAULT_NIL,
edit_ignore_keys = DEFAULT_NIL, edit_ignore_keys = DEFAULT_NIL,
@ -2028,11 +2029,17 @@ function FilteredList:setFilter(filter, pos)
-- start matches at non-space or non-punctuation. this allows -- start matches at non-space or non-punctuation. this allows
-- punctuation itself to be matched if that is useful (e.g. -- punctuation itself to be matched if that is useful (e.g.
-- filenames or parameter names) -- filenames or parameter names)
if key ~= '' and if key ~= '' then
not search_key:match('%f[^%p\x00]'..key) and if not self.case_sensitive then
search_key = string.lower(search_key)
key = string.lower(key)
end
if not search_key:match('%f[^%p\x00]'..key) and
not search_key:match('%f[^%s\x00]'..key) then not search_key:match('%f[^%s\x00]'..key) then
ok = false ok = false
break break
end
end end
end end
if ok then if ok then