diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-02-05 20:50:31 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-02-05 21:15:42 -0800 |
| commit | ef41e8c9a54119628aa8cffb193e42782e69563f (patch) | |
| tree | 1e3492386a7e038850962003157eb42d3becacbb /state.lua | |
| parent | f3ebbfd63352865d07441d1165b4816be3d78b6d (diff) | |
| download | mpv-iptv-menu-ef41e8c9a54119628aa8cffb193e42782e69563f.tar.gz mpv-iptv-menu-ef41e8c9a54119628aa8cffb193e42782e69563f.tar.xz | |
support searching currently playing programmes
Diffstat (limited to 'state.lua')
| -rw-r--r-- | state.lua | 52 |
1 files changed, 23 insertions, 29 deletions
@@ -213,6 +213,24 @@ function menu_mt:set_search_text(str, pos, term, filter) self:update_search_matches() end +function menu_mt:_match_fields(v, fields, case_sensitive) + local nm = fields.name and + util.find_matches( + v.name, self.search_term, case_sensitive) + local im = fields.info and + util.find_matches( + v.info, self.search_term, case_sensitive) + + if nm or im 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. + return setmetatable( + {matches = nm, info_matches = im}, {__index = v}) + end +end + +local F_NAME = {name = true} function menu_mt:update_search_matches() if not self.search_filter and #self.search_term == 0 then self.options = self.search_options @@ -224,35 +242,11 @@ function menu_mt:update_search_matches() local options = {} for _, v in ipairs(self.search_options) do - if not self.search_filter or self.search_filter(v) then - local matches - - local name = v.name - if not case_sensitive then - name = name:lower() - end - - local i, j = 0, 0 - while true do - i, j = name:find(self.search_term, j + 1, true) - -- j < i avoids infinite loop on empty term - if not i or j < i then - break - end - matches = matches or {} - matches[#matches+1] = {start = i, stop = j} - end - - 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}) - elseif i then - options[#options+1] = v - end + local fields = not self.search_filter and F_NAME or + self.search_filter(v) + if fields then + options[#options+1] = self.search_term == '' and v or + self:_match_fields(v, fields, case_sensitive) end end |
