mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-01-03 08:44:29 +01:00
Add a button to copy the current selection when creating highlights
This commit is contained in:
parent
409ac0b9f8
commit
a3e0461c73
3 changed files with 19 additions and 2 deletions
|
|
@ -126,7 +126,7 @@ def map_to_iframe_coords(point):
|
|||
def create_bar():
|
||||
ans = E.div(
|
||||
id=unique_id('annot-bar'),
|
||||
style=f'height: {BAR_SIZE}px; width: 100vw; display: flex; justify-content: space-between;',
|
||||
style=f'height: {BAR_SIZE}px; max-height: {BAR_SIZE}px; width: 100vw; display: flex; justify-content: space-between;',
|
||||
)
|
||||
return ans
|
||||
|
||||
|
|
@ -167,7 +167,11 @@ def button(bar, icon, tt, action):
|
|||
container.appendChild(tb)
|
||||
button(tb, 'close', _('Cancel creation of highlight'), self.hide)
|
||||
button(tb, 'chevron-up', _('Scroll up'), self.scroll_up)
|
||||
button(tb, 'check', _('Finish creation of highlight'), self.accept)
|
||||
tb.appendChild(E.span(style=f'height: {tb.style.height}'))
|
||||
if ui_operations.copy_selection:
|
||||
button(tb.lastChild, 'copy', _('Copy to clipboard'), self.copy_to_clipboard)
|
||||
tb.lastChild.appendChild(E.span('\xa0'))
|
||||
button(tb.lastChild, 'check', _('Finish creation of highlight'), self.accept)
|
||||
|
||||
middle = E.div(id=unique_id('middle'), style='display: none')
|
||||
self.middle_id = middle.id
|
||||
|
|
@ -200,6 +204,9 @@ def button(bar, icon, tt, action):
|
|||
container.addEventListener('mousemove', self.mousemove_on_container, {'passive': False})
|
||||
container.addEventListener('keydown', self.on_keydown, {'passive': False})
|
||||
|
||||
def copy_to_clipboard(self):
|
||||
self.view.iframe_wrapper.send_message('copy_selection')
|
||||
|
||||
def scroll_up(self):
|
||||
self.send_message('scroll', backwards=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ def __init__(self):
|
|||
'show_search_result': self.show_search_result,
|
||||
'handle_navigation_shortcut': self.on_handle_navigation_shortcut,
|
||||
'annotations': self.annotations_msg_received,
|
||||
'copy_selection': self.copy_selection,
|
||||
}
|
||||
self.comm = IframeClient(handlers)
|
||||
self.last_window_ypos = 0
|
||||
|
|
@ -698,5 +699,10 @@ def apply_highlights_on_load(self, highlights):
|
|||
unwrap_crw(crw)
|
||||
v'delete self.annot_id_uuid_map[crw]'
|
||||
|
||||
def copy_selection(self):
|
||||
text = window.getSelection().toString()
|
||||
if text:
|
||||
self.send_message('copy_text_to_clipboard', text=text)
|
||||
|
||||
def main():
|
||||
main.boss = IframeBoss()
|
||||
|
|
|
|||
|
|
@ -263,6 +263,10 @@ def __init__(self, container):
|
|||
ui_operations.search_result_not_found(data.search_result)
|
||||
,
|
||||
'annotations': self.on_annotations_message,
|
||||
'copy_text_to_clipboard': def(data):
|
||||
if ui_operations.copy_selection:
|
||||
ui_operations.copy_selection(data.text)
|
||||
,
|
||||
}
|
||||
entry_point = None if runtime.is_standalone_viewer else 'read_book.iframe'
|
||||
if runtime.is_standalone_viewer:
|
||||
|
|
|
|||
Loading…
Reference in a new issue