summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua38
1 files changed, 28 insertions, 10 deletions
diff --git a/main.lua b/main.lua
index cb99d65..d44548a 100644
--- a/main.lua
+++ b/main.lua
@@ -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)