diff options
| -rw-r--r-- | rt.lua | 16 | ||||
| -rw-r--r-- | state.lua | 15 |
2 files changed, 19 insertions, 12 deletions
@@ -167,8 +167,7 @@ local function save_favourites() end local function set_cursor(pos, opts) - local moved = state:menu():set_cursor(pos, osd:menu_lines(state), opts) - if moved then + if state:menu():set_cursor(pos, osd:menu_lines(state), opts) then osd:dirty() end end @@ -609,11 +608,7 @@ function rt.start_search() ' <colour.info>(<num_matches>/<num_total>)' if menu.type == 'search' then - -- 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:save_checkpoint() menu.title = title menu.search_active = true menu:set_search_cursor(#menu.search_text + 1) @@ -643,11 +638,8 @@ end function rt.cancel_search() local menu = state:menu() - -- cancelling resumed search restores previous state - if menu.prev_search_text then - menu:set_search_text(menu.prev_search_text) - menu.cursor = menu.prev_cursor - menu.view_top = menu.prev_view_top + if menu.checkpoint then + menu:restore_checkpoint() rt.end_search() return end @@ -82,6 +82,21 @@ function mt:insert_favourite_before_next_in_menu(id) self:add_favourite(id) end +function menu_mt:save_checkpoint() + self.checkpoint = { + search_text = self.search_text, + cursor = self.cursor, + view_top = self.view_top, + } +end + +function menu_mt:restore_checkpoint() + local t = self.checkpoint + self:set_search_text(t.search_text) + self.cursor = t.cursor + self.view_top = t.view_top +end + function menu_mt:set_cursor(pos, lines, opts) local pos = math.max(1, math.min(pos, #self.options)) local top = self.view_top |
