From 82526665364389d92e0f2c33eba04678275863bb Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 27 Jan 2026 01:12:16 -0800 Subject: on-demand calculation and update of option info Using metatables to calculate info strings on render, we can avoid precomputing it for all options when generating the menu, making certain menus open much faster. This also allows us to update dynamic info, e.g. the currently programme, while the menu is open. --- state.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'state.lua') diff --git a/state.lua b/state.lua index da26a9a..a88fe41 100644 --- a/state.lua +++ b/state.lua @@ -167,7 +167,7 @@ function menu_mt:update_search_matches() local options = {} for _, v in ipairs(self.search_options) do - local matches = {} + local matches local name = v.name if not case_sensitive then @@ -180,13 +180,17 @@ function menu_mt:update_search_matches() if not i then break end + matches = matches or {} matches[#matches+1] = {start = i, stop = j} end - if #matches > 0 then - local t = util.copy_table(v) - t.matches = matches - options[#options+1] = t + if matches then + -- search options may contain dynamic data that is + -- updated on redraw. using a proxy table instead of + -- copying prevents potential updates on every change + -- of search text. + options[#options+1] = setmetatable( + {matches = matches}, {__index = v}) end end -- cgit v1.2.3-70-g09d2