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
- `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
- `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
- 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.

@ -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