diff --git a/docs/changelog.txt b/docs/changelog.txt index 679ba6d99..9dda06bec 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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. diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index db5a9d59c..1d70647f7 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -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 ------------ diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index aa18d9fa9..797bd8da4 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -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