diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-04 00:20:28 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-04 00:20:28 -0800 |
| commit | d866a7b168a530eacb88b5ae9e84fc53b44952c5 (patch) | |
| tree | f4f18741ce8e5259b51fad9abc7e25356e18d0e4 | |
| parent | 89e9440d737fad09e41428b83209bf89a77dbd9d (diff) | |
| download | mpv-iptv-menu-d866a7b168a530eacb88b5ae9e84fc53b44952c5.tar.gz mpv-iptv-menu-d866a7b168a530eacb88b5ae9e84fc53b44952c5.tar.xz | |
restore previous state when cancelling resumed search
| -rw-r--r-- | main.lua | 38 |
1 files changed, 28 insertions, 10 deletions
@@ -731,7 +731,6 @@ local function update_search_matches() end menu.options = options - update_osd() end local function search_input_char(event) @@ -744,6 +743,7 @@ local function search_input_char(event) event.key_text .. menu.search_text:sub(menu.search_cursor) menu.search_cursor = menu.search_cursor + #event.key_text update_search_matches() + update_osd() end local function search_input_bs() @@ -757,6 +757,7 @@ local function search_input_bs() menu.search_text:sub(menu.search_cursor) menu.search_cursor = pos update_search_matches() + update_osd() end local function search_input_del() @@ -769,6 +770,7 @@ local function search_input_del() menu.search_text:sub(util.utf8_seek( menu.search_text, menu.search_cursor, 1)) update_search_matches() + update_osd() end local function set_search_cursor(pos) @@ -807,19 +809,23 @@ local bind_menu_keys local function start_search() local menu = menus[depth] + local title = 'Searching: <text_with_cursor>' .. + ' <colours.info>(<num_matches>/<num_total>)' + if menu.type == 'search' then - -- resume search - menu.title = 'Searching: <text_with_cursor>' .. - ' <colours.info>(<num_matches>/<num_total>)' + -- resuming search, save previous state + menu.prev_search_text = menu.search_text + menu.prev_cursor = menu.cursor + menu.prev_view_top = menu.view_top + + menu.title = title menu.search_active = true menu.search_cursor = #menu.search_text + 1 menu.cursor = 1 menu.view_top = 1 - update_osd() else push_menu({ - title = 'Searching: <text_with_cursor>' .. - ' <colours.info>(<num_matches>/<num_total>)', + title = title, type = 'search', search_active = true, search_options = search_menu_options(menu.options), @@ -829,6 +835,7 @@ local function start_search() update_search_matches() end + update_osd() bind_search_keys() end @@ -842,7 +849,19 @@ local function end_search() end local function cancel_search() - menus[depth].search_active = false + local menu = menus[depth] + + -- cancelling resumed search restores previous state + if menu.prev_search_text then + menu.search_text = menu.prev_search_text + menu.cursor = menu.prev_cursor + menu.view_top = menu.prev_view_top + update_search_matches() + end_search() + return + end + + menu.search_active = false depth = depth - 1 update_osd() bind_menu_keys() @@ -864,9 +883,8 @@ local function toggle_menu_sort() if menu.type == 'search' then update_search_matches() - else - update_osd() end + update_osd() end local function bind_key(key, func, opts) |
