From 1247a0d512c1724410496fa5d8fcc3098e56eb87 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 3 Sep 2020 23:29:50 +0530 Subject: [PATCH] Server viewer: Fix error when triple clicking in firefox Firefox does not support extending selection to pargraphs so instead extend to line. --- src/pyj/read_book/iframe.pyj | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index edf6f8e367..5b1eb777ef 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -741,10 +741,19 @@ class IframeBoss: self.on_handle_navigation_shortcut(data) elif dtype is 'extend-to-paragraph': sel = window.getSelection() - sel.modify('extend', 'forward', 'paragraphboundary') - end_node, end_offset = sel.focusNode, sel.focusOffset - sel.modify('extend', 'backward', 'paragraphboundary') - sel.setBaseAndExtent(sel.focusNode, sel.focusOffset, end_node, end_offset) + try: + try: + sel.modify('extend', 'forward', 'paragraphboundary') + except: + sel.modify('extend', 'forward', 'lineboundary') + end_node, end_offset = sel.focusNode, sel.focusOffset + try: + sel.modify('extend', 'backward', 'paragraphboundary') + except: + sel.modify('extend', 'backward', 'lineboundary') + sel.setBaseAndExtent(sel.focusNode, sel.focusOffset, end_node, end_offset) + except: + (console.error or console.log)('Failed to extend selection to paragraph') elif dtype is 'drag-scroll': self.scroll_to_extend_annotation(data.backwards) elif dtype is 'edit-highlight':