mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Different approach: render all text layers while selecting (WIP).
This commit is contained in:
parent
786659dc1b
commit
4985f7ca1c
2 changed files with 37 additions and 10 deletions
|
@ -405,15 +405,37 @@ define [
|
|||
scope.adjustingScroll = true
|
||||
element.scrollTop(currentScrollTop + delta)
|
||||
|
||||
element.on 'mouseover', '.pdf-page-container', (e) ->
|
||||
pdfPageEl = $(e.currentTarget)
|
||||
element.on 'mousedown', (e) ->
|
||||
if !_hasSelection()
|
||||
console.log 'adding class'
|
||||
element.addClass 'pdfjs-viewer-show-text'
|
||||
$(document.body).one 'mouseup', _handleSelectionMouseUp
|
||||
|
||||
pdfPageEl.find('.plv-text-layer').addClass('plv-text-layer-visible')
|
||||
pdfPageEl.prev().find('.plv-text-layer').addClass('plv-text-layer-visible')
|
||||
pdfPageEl.next().find('.plv-text-layer').addClass('plv-text-layer-visible')
|
||||
_handleSelectionMouseUp = () ->
|
||||
window.setTimeout _removeClassIfNoSelection, 10
|
||||
|
||||
element.on 'mouseout', '.pdf-page-container', (e) ->
|
||||
$('.plv-text-layer-visible').removeClass('plv-text-layer-visible')
|
||||
_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
|
||||
|
||||
_isSelectionWithinPDF = (selection) ->
|
||||
if selection.rangeCount == 0
|
||||
return false
|
||||
selectionAncestorNode = selection.getRangeAt(0).commonAncestorContainer
|
||||
return element.find(selectionAncestorNode).length > 0 or element.is(selectionAncestorNode)
|
||||
|
||||
element.on 'scroll', () ->
|
||||
#console.log 'scroll event', element.scrollTop(), 'adjusting?', scope.adjustingScroll
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
.full-size;
|
||||
background-color: @gray-lighter;
|
||||
overflow: scroll;
|
||||
user-select: none;
|
||||
canvas, div.pdf-canvas {
|
||||
background: white;
|
||||
box-shadow: black 0px 0px 10px;
|
||||
|
@ -341,10 +342,14 @@
|
|||
|
||||
.plv-text-layer {
|
||||
display: none;
|
||||
user-select: text;
|
||||
|
||||
.pdf-page-container:hover &,
|
||||
.pdfjs-viewer-show-text & {
|
||||
display: block;
|
||||
}
|
||||
|
||||
& > div {
|
||||
color: red;
|
||||
}
|
||||
&.plv-text-layer-visible {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue