Fix #2089461 [Calibre Editor mouse busy for replace all on marked text](https://bugs.launchpad.net/calibre/+bug/2089461)

This commit is contained in:
Kovid Goyal 2024-11-24 12:10:34 +05:30
parent 149ccef977
commit 90b33c9648
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1582,32 +1582,41 @@ def run_search(
count_message(replace, count, show_diff=replace, count_map=count_map) count_message(replace, count, show_diff=replace, count_map=count_map)
return count return count
with BusyCursor(): post_search_action = None
if action == 'find': try:
return do_find() with BusyCursor():
if action == 'replace': if action == 'find':
return do_replace() return do_find()
if action == 'replace-find' and do_replace(): if action == 'replace':
return do_find() return do_replace()
if action == 'replace-all': if action == 'replace-find' and do_replace():
if marked: return do_find()
show_result_dialog = True if action == 'replace-all':
for p, repl in searches: if marked:
if getattr(getattr(repl, 'func', None), 'suppress_result_dialog', False): show_result_dialog = True
show_result_dialog = False for p, repl in searches:
break if getattr(getattr(repl, 'func', None), 'suppress_result_dialog', False):
return count_message(True, sum(editor.all_in_marked(p, repl) for p, repl in searches), show_dialog=show_result_dialog) show_result_dialog = False
add_savepoint(_('Before: Replace all')) break
count = do_all() res_count = sum(editor.all_in_marked(p, repl) for p, repl in searches)
if count == 0: post_search_action = partial(count_message, True, res_count, show_dialog=show_result_dialog)
rewind_savepoint() return
else: add_savepoint(_('Before: Replace all'))
set_modified() count = do_all()
return if count == 0:
if action == 'count': rewind_savepoint()
if marked: else:
return count_message(False, sum(editor.all_in_marked(p) for p, __ in searches)) set_modified()
return do_all(replace=False) return
if action == 'count':
if marked:
res_count = sum(editor.all_in_marked(p) for p, __ in searches)
post_search_action = partial(count_message, False, res_count)
return
return do_all(replace=False)
finally:
if post_search_action is not None:
post_search_action()
if __name__ == '__main__': if __name__ == '__main__':