The copy button in the selection bar should work in the browser viewer as well

This commit is contained in:
Kovid Goyal 2020-07-27 12:35:26 +05:30
parent 593d652150
commit d8979c20cb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 9 additions and 8 deletions

View File

@ -409,8 +409,7 @@ class CreateAnnotation: # {{{
container.appendChild(tb) container.appendChild(tb)
button('close', tb.firstChild, 'close', _('Cancel creation of highlight') + ' [Esc]', self.hide) button('close', tb.firstChild, 'close', _('Cancel creation of highlight') + ' [Esc]', self.hide)
button('up', tb.firstChild.nextSibling, 'chevron-up', _('Scroll up') + ' [Up]', self.button_scroll.bind(None, True)) button('up', tb.firstChild.nextSibling, 'chevron-up', _('Scroll up') + ' [Up]', self.button_scroll.bind(None, True))
if ui_operations.copy_selection: button('copy', tb.lastChild, 'copy', _('Copy to clipboard'), self.copy_to_clipboard)
button('copy', tb.lastChild, 'copy', _('Copy to clipboard'), self.copy_to_clipboard)
button('finish', tb.lastChild, 'check', _('Finish creation of highlight') + ' [Enter]', self.accept) button('finish', tb.lastChild, 'check', _('Finish creation of highlight') + ' [Enter]', self.accept)
middle = E.div(id=unique_id('middle'), style='display: none; text-align: center; z-index: 90000') middle = E.div(id=unique_id('middle'), style='display: none; text-align: center; z-index: 90000')
@ -449,7 +448,7 @@ class CreateAnnotation: # {{{
container.addEventListener('keydown', self.on_keydown, {'passive': False}) container.addEventListener('keydown', self.on_keydown, {'passive': False})
def copy_to_clipboard(self): def copy_to_clipboard(self):
self.view.iframe_wrapper.send_message('copy_selection') ui_operations.copy_selection(self.view.currently_showing.selection.text or '')
@property @property
def middle(self): def middle(self):

View File

@ -42,8 +42,7 @@ class SelectionBar:
ans.style.marginLeft = ans.style.marginRight = '0.5rem' ans.style.marginLeft = ans.style.marginRight = '0.5rem'
return ans return ans
if ui_operations.copy_selection: bar.appendChild(cb('copy', _('Copy to clipboard'), self.copy_to_clipboard))
bar.appendChild(cb('copy', _('Copy to clipboard'), self.copy_to_clipboard))
bar.appendChild(cb('library', _('Lookup/search selected word'), self.lookup)) bar.appendChild(cb('library', _('Lookup/search selected word'), self.lookup))
bar.appendChild(cb('highlight', _('Highlight selection'), self.create_highlight)) bar.appendChild(cb('highlight', _('Highlight selection'), self.create_highlight))
bar.appendChild(cb('search', _('Search for selection on the net'), self.internet_search)) bar.appendChild(cb('search', _('Search for selection on the net'), self.internet_search))
@ -75,7 +74,7 @@ class SelectionBar:
return self.container.style.display is not 'none' return self.container.style.display is not 'none'
def copy_to_clipboard(self): def copy_to_clipboard(self):
if self.view.currently_showing.selection.text and ui_operations.copy_selection: if self.view.currently_showing.selection.text:
ui_operations.copy_selection(self.view.currently_showing.selection.text) ui_operations.copy_selection(self.view.currently_showing.selection.text)
def lookup(self): def lookup(self):

View File

@ -77,6 +77,10 @@ class ReadUI:
ui_operations.annotations_synced = self.annotations_synced.bind(self) ui_operations.annotations_synced = self.annotations_synced.bind(self)
ui_operations.open_url = def(url): ui_operations.open_url = def(url):
window.open(url, '_blank') window.open(url, '_blank')
ui_operations.copy_selection = def(text):
window.navigator.clipboard.writeText(text or '').then(def (): pass;, def():
error_dialog(_('Could not copy to clipboard'), _('No permission to write to clipboard'))
)
def on_resize(self): def on_resize(self):
self.view.on_resize() self.view.on_resize()

View File

@ -272,8 +272,7 @@ class View:
, ,
'annotations': self.on_annotations_message, 'annotations': self.on_annotations_message,
'copy_text_to_clipboard': def(data): 'copy_text_to_clipboard': def(data):
if ui_operations.copy_selection: ui_operations.copy_selection(data.text)
ui_operations.copy_selection(data.text)
, ,
'view_image': def(data): 'view_image': def(data):
if ui_operations.view_image: if ui_operations.view_image: