Selection bar should not popup during searches

This commit is contained in:
Kovid Goyal 2020-08-06 12:23:55 +05:30
parent 7006b69901
commit 0319f8325a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 3 deletions

View File

@ -112,6 +112,7 @@ class IframeBoss:
def __init__(self): def __init__(self):
window.navigator.epubReadingSystem = EPUBReadingSystem() window.navigator.epubReadingSystem = EPUBReadingSystem()
self.last_cfi = None self.last_cfi = None
self.last_search_at = -1001
self.reference_mode_enabled = False self.reference_mode_enabled = False
self.replace_history_on_next_cfi_update = True self.replace_history_on_next_cfi_update = True
self.blob_url_map = {} self.blob_url_map = {}
@ -528,9 +529,10 @@ class IframeBoss:
if not collapsed: if not collapsed:
text = sel.toString() text = sel.toString()
annot_id = highlight_associated_with_selection(sel, annot_id_uuid_map) annot_id = highlight_associated_with_selection(sel, annot_id_uuid_map)
by_search = window.performance.now() - self.last_search_at < 1000
self.send_message( self.send_message(
'selectionchange', text=text, empty=v'!!collapsed', annot_id=annot_id, 'selectionchange', text=text, empty=v'!!collapsed', annot_id=annot_id,
drag_mouse_position=drag_mouse_position, drag_mouse_position=drag_mouse_position, selection_change_caused_by_search=by_search,
selection_extents=selection_extents(current_layout_mode() is 'flow', True)) selection_extents=selection_extents(current_layout_mode() is 'flow', True))
def onresize_stage2(self): def onresize_stage2(self):
@ -680,6 +682,7 @@ class IframeBoss:
self.scroll_to_ref(refnum) self.scroll_to_ref(refnum)
def find(self, data, from_load): def find(self, data, from_load):
self.last_search_at = window.performance.now()
if data.searched_in_spine: if data.searched_in_spine:
window.getSelection().removeAllRanges() window.getSelection().removeAllRanges()
if window.find(data.text, False, data.backwards, from_load and data.backwards): if window.find(data.text, False, data.backwards, from_load and data.backwards):
@ -693,6 +696,7 @@ class IframeBoss:
self.send_message('find_in_spine', text=data.text, backwards=data.backwards, searched_in_spine=data.searched_in_spine) self.send_message('find_in_spine', text=data.text, backwards=data.backwards, searched_in_spine=data.searched_in_spine)
def show_search_result(self, data, from_load): def show_search_result(self, data, from_load):
self.last_search_at = window.performance.now()
if select_search_result(data.search_result): if select_search_result(data.search_result):
self.ensure_selection_visible() self.ensure_selection_visible()
else: else:

View File

@ -548,7 +548,7 @@ class SelectionBar:
self.right_handle.style.display = 'none' self.right_handle.style.display = 'none'
self.editor.style.display = 'none' self.editor.style.display = 'none'
if not cs or cs.empty or jstype(cs.drag_mouse_position.x) is 'number': if not cs or cs.empty or jstype(cs.drag_mouse_position.x) is 'number' or cs.selection_change_caused_by_search:
return self.hide() return self.hide()
if not cs.start.onscreen and not cs.end.onscreen: if not cs.start.onscreen and not cs.end.onscreen:

View File

@ -536,7 +536,8 @@ class View:
self.currently_showing.selection = { self.currently_showing.selection = {
'text': data.text, 'empty': data.empty, 'start': data.selection_extents.start, 'text': data.text, 'empty': data.empty, 'start': data.selection_extents.start,
'end': data.selection_extents.end, 'annot_id': data.annot_id, 'end': data.selection_extents.end, 'annot_id': data.annot_id,
'drag_mouse_position': data.drag_mouse_position 'drag_mouse_position': data.drag_mouse_position,
'selection_change_caused_by_search': data.selection_change_caused_by_search
} }
if ui_operations.selection_changed: if ui_operations.selection_changed:
ui_operations.selection_changed(self.currently_showing.selection.text) ui_operations.selection_changed(self.currently_showing.selection.text)