mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Viewer: Fix selection popup bar not always close to mouse when ending select-to-drag
This commit is contained in:
parent
2e0a2a6e33
commit
8bd7109300
@ -536,15 +536,20 @@ class IframeBoss:
|
|||||||
text = ''
|
text = ''
|
||||||
annot_id = None
|
annot_id = None
|
||||||
collapsed = not sel or sel.isCollapsed
|
collapsed = not sel or sel.isCollapsed
|
||||||
|
start_is_anchor = True
|
||||||
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)
|
||||||
|
r = sel.getRangeAt(0)
|
||||||
|
start_is_anchor = r.startContainer is sel.anchorNode and r.startOffset is sel.anchorOffset
|
||||||
by_search = window.performance.now() - self.last_search_at < 1000
|
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, selection_change_caused_by_search=by_search,
|
drag_mouse_position=drag_mouse_position, selection_change_caused_by_search=by_search,
|
||||||
selection_extents=selection_extents(current_layout_mode() is 'flow'),
|
selection_extents=selection_extents(current_layout_mode() is 'flow'),
|
||||||
rtl=scroll_viewport.rtl, vertical=scroll_viewport.vertical_writing_mode)
|
rtl=scroll_viewport.rtl, vertical=scroll_viewport.vertical_writing_mode,
|
||||||
|
start_is_anchor=start_is_anchor
|
||||||
|
)
|
||||||
|
|
||||||
def onresize_stage2(self):
|
def onresize_stage2(self):
|
||||||
if scroll_viewport.width() is self.last_window_width and scroll_viewport.height() is self.last_window_height:
|
if scroll_viewport.width() is self.last_window_width and scroll_viewport.height() is self.last_window_height:
|
||||||
|
@ -687,7 +687,11 @@ class SelectionBar:
|
|||||||
|
|
||||||
# We try to place the bar near the last dragged handle so it shows up
|
# We try to place the bar near the last dragged handle so it shows up
|
||||||
# close to current mouse position. We assume it is the "end" handle.
|
# close to current mouse position. We assume it is the "end" handle.
|
||||||
if dragged_handle and dragged_handle is not self.end_handle_id:
|
if dragged_handle:
|
||||||
|
if dragged_handle is not self.end_handle_id:
|
||||||
|
start, end = end, start
|
||||||
|
else:
|
||||||
|
if not cs.start_is_anchor:
|
||||||
start, end = end, start
|
start, end = end, start
|
||||||
if not end.onscreen and start.onscreen:
|
if not end.onscreen and start.onscreen:
|
||||||
start, end = end, start
|
start, end = end, start
|
||||||
|
@ -552,7 +552,8 @@ class View:
|
|||||||
'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,
|
'selection_change_caused_by_search': data.selection_change_caused_by_search,
|
||||||
'rtl': data.rtl, 'vertical': data.vertical
|
'rtl': data.rtl, 'vertical': data.vertical,
|
||||||
|
'start_is_anchor': data.start_is_anchor
|
||||||
}
|
}
|
||||||
if ui_operations.selection_changed:
|
if ui_operations.selection_changed:
|
||||||
ui_operations.selection_changed(self.currently_showing.selection.text, self.currently_showing.selection.annot_id)
|
ui_operations.selection_changed(self.currently_showing.selection.text, self.currently_showing.selection.annot_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user