From fbaa918927ae5b398670e2a38564fa0e1c2a7508 Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Thu, 15 Jun 2017 11:34:24 +0100 Subject: [PATCH] Do not show the text layer when the user clicks outside pages. Remove some debug statements. --- .../ide/pdfng/directives/pdfViewer.coffee | 19 +++++++++---------- .../public/stylesheets/app/editor/pdf.less | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee b/services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee index 0dd9e58832..0543d64459 100644 --- a/services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee +++ b/services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee @@ -406,8 +406,14 @@ define [ element.scrollTop(currentScrollTop + delta) element.on 'mousedown', (e) -> - if !_hasSelection() - console.log 'adding class' + # We're checking that the event target isn't the directive root element + # to make sure that the click was within a PDF page - no point in showing + # the text layer when the click is outside. + # If the user clicks a PDF page, the mousedown target will be the canvas + # element (or the text layer one). Alternatively, if the event target is + # the root element, we can assume that the user has clicked either the + # grey background area or the scrollbars. + if e.target != element[0] and !_hasSelection() element.addClass 'pdfjs-viewer-show-text' $(document.body).one 'mouseup', _handleSelectionMouseUp @@ -416,20 +422,13 @@ define [ _removeClassIfNoSelection = () -> if _hasSelection() - console.log 'has selection, keeping class' $(document.body).one 'mouseup', _handleSelectionMouseUp else - console.log 'no selection, removing class' element.removeClass 'pdfjs-viewer-show-text' _hasSelection = () -> selection = window.getSelection() - if _isSelectionWithinPDF(selection) and selection.toString() != '' - console.log 'selection within and not empty' + selection.toString() - return true - else - console.log 'selection outside or empty' - return false + return _isSelectionWithinPDF(selection) and selection.toString() != '' _isSelectionWithinPDF = (selection) -> if selection.rangeCount == 0 diff --git a/services/web/public/stylesheets/app/editor/pdf.less b/services/web/public/stylesheets/app/editor/pdf.less index 728e11d6a8..284dfd81a1 100644 --- a/services/web/public/stylesheets/app/editor/pdf.less +++ b/services/web/public/stylesheets/app/editor/pdf.less @@ -23,7 +23,6 @@ .full-size; background-color: @gray-lighter; overflow: scroll; - user-select: none; canvas, div.pdf-canvas { background: white; box-shadow: black 0px 0px 10px; @@ -38,6 +37,7 @@ margin: 10px auto; padding: 0 10px; box-sizing: content-box; + user-select: none; } } .progress-thin {