Merge pull request #3381 from myk002/myk_substring_filter

make full text search configurable for list filters
develop
Myk 2023-05-17 11:26:45 -07:00 committed by GitHub
commit 29ece9ce3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

@ -50,6 +50,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Misc Improvements ## Misc Improvements
- `orders`: update orders in orders library for prepared meals, bins, archer uniforms, and weapons - `orders`: update orders in orders library for prepared meals, bins, archer uniforms, and weapons
- Terminal console no longer appears in front of the game window on startup - 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 - `gui/design`: Improved performance for drawing shapes
- Dreamfort: improve traffic patterns throughout the fortress (stockpiles and zones are still not working, pending updates in `quickfort`) - Dreamfort: improve traffic patterns throughout the fortress (stockpiles and zones are still not working, pending updates in `quickfort`)
- Core: For debugging purposes, you can now pass ``--disable-dfhack`` on the Dwarf Fortress commandline or specify ``DFHACK_DISABLE=1`` in the environment to disable DFHack for the current session. - Core: For debugging purposes, you can now pass ``--disable-dfhack`` on the Dwarf Fortress commandline or specify ``DFHACK_DISABLE=1`` in the environment to disable DFHack for the current session.

@ -5106,6 +5106,14 @@ The widget implements:
Same as with an ordinary list. 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 TabBar class
------------ ------------

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