mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a button to copy the current selection when creating highlights
This commit is contained in:
parent
409ac0b9f8
commit
a3e0461c73
@ -126,7 +126,7 @@ BAR_SIZE = 32
|
||||
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 @@ class CreateAnnotation:
|
||||
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 @@ class CreateAnnotation:
|
||||
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 @@ class IframeBoss:
|
||||
'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 @@ class IframeBoss:
|
||||
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 @@ class View:
|
||||
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…
x
Reference in New Issue
Block a user