mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Track the selection position in the chrome
This commit is contained in:
parent
23fb259c42
commit
05516bfd54
@ -505,6 +505,9 @@ class IframeBoss:
|
|||||||
fpf = progress_frac()
|
fpf = progress_frac()
|
||||||
self.send_message(
|
self.send_message(
|
||||||
'update_progress_frac', progress_frac=pf, file_progress_frac=fpf)
|
'update_progress_frac', progress_frac=pf, file_progress_frac=fpf)
|
||||||
|
sel = window.getSelection()
|
||||||
|
if sel and not sel.isCollapsed:
|
||||||
|
self.send_message('update_selection_position', selection_extents=selection_extents(current_layout_mode() is 'flow'))
|
||||||
|
|
||||||
def onresize(self):
|
def onresize(self):
|
||||||
self.send_message('request_size')
|
self.send_message('request_size')
|
||||||
@ -516,8 +519,16 @@ class IframeBoss:
|
|||||||
self.onresize_stage2()
|
self.onresize_stage2()
|
||||||
|
|
||||||
def onselectionchange(self):
|
def onselectionchange(self):
|
||||||
if self.content_ready:
|
if not self.content_ready:
|
||||||
self.send_message('selectionchange', text=document.getSelection().toString())
|
return
|
||||||
|
sel = window.getSelection()
|
||||||
|
text = ''
|
||||||
|
collapsed = not sel or sel.isCollapsed
|
||||||
|
if not collapsed:
|
||||||
|
text = sel.toString()
|
||||||
|
self.send_message(
|
||||||
|
'selectionchange', text=text, empty=v'!!collapsed',
|
||||||
|
selection_extents=selection_extents(current_layout_mode() is 'flow'))
|
||||||
|
|
||||||
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:
|
||||||
|
@ -261,6 +261,7 @@ class View:
|
|||||||
'request_size': self.on_request_size,
|
'request_size': self.on_request_size,
|
||||||
'scroll_to_anchor': self.on_scroll_to_anchor,
|
'scroll_to_anchor': self.on_scroll_to_anchor,
|
||||||
'selectionchange': self.on_selection_change,
|
'selectionchange': self.on_selection_change,
|
||||||
|
'update_selection_position': self.update_selection_position,
|
||||||
'columns_per_screen_changed': self.on_columns_per_screen_changed,
|
'columns_per_screen_changed': self.on_columns_per_screen_changed,
|
||||||
'show_chrome': self.show_chrome,
|
'show_chrome': self.show_chrome,
|
||||||
'show_footnote': self.on_show_footnote,
|
'show_footnote': self.on_show_footnote,
|
||||||
@ -513,8 +514,15 @@ class View:
|
|||||||
|
|
||||||
def on_selection_change(self, data):
|
def on_selection_change(self, data):
|
||||||
self.currently_showing.selected_text = data.text
|
self.currently_showing.selected_text = data.text
|
||||||
|
self.currently_showing.has_selection = not data.empty
|
||||||
|
self.currently_showing.selection_start = data.selection_extents.start
|
||||||
|
self.currently_showing.selection_end = data.selection_extents.end
|
||||||
if ui_operations.selection_changed:
|
if ui_operations.selection_changed:
|
||||||
ui_operations.selection_changed(data.text)
|
ui_operations.selection_changed(self.currently_showing.selected_text)
|
||||||
|
|
||||||
|
def update_selection_position(self, data):
|
||||||
|
self.currently_showing.selection_start = data.selection_extents.start
|
||||||
|
self.currently_showing.selection_end = data.selection_extents.end
|
||||||
|
|
||||||
def on_columns_per_screen_changed(self, data):
|
def on_columns_per_screen_changed(self, data):
|
||||||
sd = get_session_data()
|
sd = get_session_data()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user