From c1b9de87d2303acecd763d71c020d70046049dc8 Mon Sep 17 00:00:00 2001 From: Robob27 Date: Mon, 6 Feb 2023 22:40:59 -0500 Subject: [PATCH 1/4] Add case_sensitive attr to FilteredList --- library/lua/gui/widgets.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index d8c605b93..61cd92cfa 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -1866,6 +1866,7 @@ end FilteredList = defclass(FilteredList, Widget) FilteredList.ATTRS { + case_sensitive = true, edit_below = false, edit_key = DEFAULT_NIL, edit_ignore_keys = DEFAULT_NIL, @@ -2026,11 +2027,17 @@ function FilteredList:setFilter(filter, pos) -- start matches at non-space or non-punctuation. this allows -- punctuation itself to be matched if that is useful (e.g. -- filenames or parameter names) - if key ~= '' and + if key ~= '' then + if self.case_sensitive and not search_key:match('%f[^%p\x00]'..key) and not search_key:match('%f[^%s\x00]'..key) then - ok = false - break + ok = false + break + elseif not string.lower(search_key):match('%f[^%p\x00]'..string.lower(key)) and + not string.lower(search_key):match('%f[^%s\x00]'..string.lower(key)) then + ok = false + break + end end end if ok then From 13440d18a85f4fb2de4f0d4f71137ff84f76dd9c Mon Sep 17 00:00:00 2001 From: Robob27 Date: Mon, 6 Feb 2023 22:48:18 -0500 Subject: [PATCH 2/4] Add case_sensitive to FilteredList docs --- docs/dev/Lua API.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 503f4bece..3580b5244 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -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 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_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. From 54560bc5dbab1b0b1ddaf26d5e73487aaf8f15fa Mon Sep 17 00:00:00 2001 From: Robob27 Date: Wed, 8 Feb 2023 02:02:50 -0500 Subject: [PATCH 3/4] Don't duplicate regex --- library/lua/gui/widgets.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 61cd92cfa..c249b579f 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -2028,15 +2028,15 @@ function FilteredList:setFilter(filter, pos) -- punctuation itself to be matched if that is useful (e.g. -- filenames or parameter names) if key ~= '' then - if self.case_sensitive and - 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 ok = false break - elseif not string.lower(search_key):match('%f[^%p\x00]'..string.lower(key)) and - not string.lower(search_key):match('%f[^%s\x00]'..string.lower(key)) then - ok = false - break end end end From 22b31bd7f1d970e65397edb5cde72dc3c4b82a24 Mon Sep 17 00:00:00 2001 From: Robob27 Date: Wed, 8 Feb 2023 12:37:35 -0500 Subject: [PATCH 4/4] Update changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ece6f04e1..fbc26f062 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -57,6 +57,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## 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. - ``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