From 726771c8d34c71f1e5ca47e043b9ce7c63838615 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 28 Nov 2022 15:49:01 -0800 Subject: [PATCH] supply default search key for tokenized text --- docs/changelog.txt | 3 ++- library/lua/gui/widgets.lua | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 6ca4995c9..f9829c382 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -115,7 +115,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``dfhack.constructions.findAtTile()``: exposed preexisting function to Lua. - ``dfhack.constructions.insert()``: exposed new function to Lua. - ``widgets.Panel``: new ``frame_style`` and ``frame_title`` attributes for drawing frames around groups of widgets -- ``widgets.EditField`` now allows other widgets to process characters that the ``on_char`` callback rejects. +- ``widgets.EditField``: now allows other widgets to process characters that the ``on_char`` callback rejects. +- ``widgets.FilteredList``: now provides a useful default search key for list items made up of text tokens instead of plain text - ``gui.Screen.show()`` now returns ``self`` as a convenience - ``gui.View.getMousePos()`` now takes an optional ``ViewRect`` parameter in case the caller wants to get the mouse pos relative to a rect that is not the frame_body (such as the frame_rect) - Lua mouse events now conform to documented behavior in `lua-api` -- ``_MOUSE_L_DOWN`` will be sent exactly once per mouse click and ``_MOUSE_L`` will be sent repeatedly as long as the button is held down. Similarly for right mouse button events. diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index e8093345f..973fe8339 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -1452,7 +1452,20 @@ function FilteredList:setFilter(filter, pos) for i,v in ipairs(self.choices) do local ok = true - local search_key = v.search_key or v.text + local search_key = v.search_key + if not search_key then + if type(v.text) ~= 'table' then + search_key = v.text + else + local texts = {} + for _,token in ipairs(v.text) do + table.insert(texts, + type(token) == 'string' and token + or getval(token.text) or '') + end + search_key = table.concat(texts, ' ') + end + end for _,key in ipairs(tokens) do key = key:escape_pattern() -- start matches at non-space or non-punctuation. this allows