diff options
-rw-r--r-- | main.lua | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -163,7 +163,7 @@ local function push_menu(t) menus[depth] = menu end -local function add_category_menu(category_id, category_name) +local function category_menu_options(category_id) local options = {} for _, v in ipairs(categories) do if tostring(v.parent_id) == category_id then @@ -175,8 +175,14 @@ local function add_category_menu(category_id, category_name) options[#options+1] = v end end + return options +end - push_menu({options=options, title=category_name}) +local function add_category_menu(category_id, category_name) + push_menu({ + options=category_menu_options(category_id), + title=category_name, + }) update_osd() end @@ -226,9 +232,22 @@ local function search_update_osd() update_osd() end +local function search_candidates(options, arr) + local arr = arr or {} + for _, v in ipairs(options) do + arr[#arr+1] = v + + if v.type == 'category' then + search_candidates( + category_menu_options(v.category_id), arr) + end + end + return arr +end + local function search_update() local matches = {} - for _, v in ipairs(menus[depth-1].options) do + for _, v in ipairs(menus[depth].candidates) do if string.find(v.name, search_text, 0, true) then matches[#matches+1] = v end @@ -303,7 +322,10 @@ local function search_start() else search_text = '' search_text_cursor = 1 - push_menu({type='search'}) + push_menu({ + type='search', + candidates=search_candidates(menu.options), + }) search_update() end |