make full text search configurable for list filters

develop
Myk Taylor 2023-05-16 12:36:58 -07:00
parent 2a734b92f7
commit 217be6b58d
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
3 changed files with 21 additions and 7 deletions

@ -47,6 +47,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Misc Improvements
- Terminal console no longer appears in front of the game window on startup
- `gui/control-panel`: new preference for whether filters in lists search for substrings in the middle of words (e.g. if set to true, then "ee" will match "steel")
- `gui/design`: Improved performance for drawing shapes
## Documentation

@ -5106,6 +5106,14 @@ The widget implements:
Same as with an ordinary list.
Filter behavior:
By default, the filter matches substrings that start at the beginning of a word
(or after any punctuation). You can instead configure filters to match any
substring with a command like::
:lua require('gui.widgets').FILTER_FULL_TEXT=true
TabBar class
------------

@ -1932,6 +1932,8 @@ end
-- Filtered List --
-------------------
FILTER_FULL_TEXT = false
FilteredList = defclass(FilteredList, Widget)
FilteredList.ATTRS {
@ -2102,19 +2104,22 @@ function FilteredList:setFilter(filter, pos)
end
for _,key in ipairs(tokens) do
key = key:escape_pattern()
-- 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 ~= '' then
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
-- the separate checks for non-space or non-punctuation allows
-- punctuation itself to be matched if that is useful (e.g.
-- filenames or parameter names)
if not FILTER_FULL_TEXT and not search_key:match('%f[^%p\x00]'..key)
and not search_key:match('%f[^%s\x00]'..key) then
ok = false
break
elseif FILTER_FULL_TEXT and not search_key:find(key) then
ok = false
break
end
end
end