mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Continuing fairexpand #6663
1. Expanding divs to improve text selection. (Yury) 2. Adding enhanceTextSelection as an option. 3. Moving feature functionality from text_layer_builder.js to text_layer.js. 4. Added expandTextDivs method to only load expanded divs on first click, and only show on subsequent clicks
This commit is contained in:
parent
31cd23a6df
commit
6faa84abdb
8 changed files with 433 additions and 36 deletions
|
@ -35,6 +35,8 @@
|
|||
* @property {number} pageIndex - The page index.
|
||||
* @property {PageViewport} viewport - The viewport of the text layer.
|
||||
* @property {PDFFindController} findController
|
||||
* @property {boolean} enhanceTextSelection - Option to turn on improved
|
||||
* text selection.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -57,6 +59,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||
this.textDivs = [];
|
||||
this.findController = options.findController || null;
|
||||
this.textLayerRenderTask = null;
|
||||
this.enhanceTextSelection = options.enhanceTextSelection;
|
||||
this._bindMouse();
|
||||
}
|
||||
|
||||
|
@ -64,9 +67,11 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||
_finishRendering: function TextLayerBuilder_finishRendering() {
|
||||
this.renderingDone = true;
|
||||
|
||||
var endOfContent = document.createElement('div');
|
||||
endOfContent.className = 'endOfContent';
|
||||
this.textLayerDiv.appendChild(endOfContent);
|
||||
if (!this.enhanceTextSelection) {
|
||||
var endOfContent = document.createElement('div');
|
||||
endOfContent.className = 'endOfContent';
|
||||
this.textLayerDiv.appendChild(endOfContent);
|
||||
}
|
||||
|
||||
this.eventBus.dispatch('textlayerrendered', {
|
||||
source: this,
|
||||
|
@ -96,7 +101,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||
container: textLayerFrag,
|
||||
viewport: this.viewport,
|
||||
textDivs: this.textDivs,
|
||||
timeout: timeout
|
||||
timeout: timeout,
|
||||
enhanceTextSelection: this.enhanceTextSelection,
|
||||
});
|
||||
this.textLayerRenderTask.promise.then(function () {
|
||||
this.textLayerDiv.appendChild(textLayerFrag);
|
||||
|
@ -314,7 +320,12 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||
*/
|
||||
_bindMouse: function TextLayerBuilder_bindMouse() {
|
||||
var div = this.textLayerDiv;
|
||||
var self = this;
|
||||
div.addEventListener('mousedown', function (e) {
|
||||
if (self.enhanceTextSelection && self.textLayerRenderTask) {
|
||||
self.textLayerRenderTask.expandTextDivs(true);
|
||||
return;
|
||||
}
|
||||
var end = div.querySelector('.endOfContent');
|
||||
if (!end) {
|
||||
return;
|
||||
|
@ -338,6 +349,10 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||
end.classList.add('active');
|
||||
});
|
||||
div.addEventListener('mouseup', function (e) {
|
||||
if (self.enhanceTextSelection && self.textLayerRenderTask) {
|
||||
self.textLayerRenderTask.expandTextDivs(false);
|
||||
return;
|
||||
}
|
||||
var end = div.querySelector('.endOfContent');
|
||||
if (!end) {
|
||||
return;
|
||||
|
@ -362,13 +377,16 @@ DefaultTextLayerFactory.prototype = {
|
|||
* @param {HTMLDivElement} textLayerDiv
|
||||
* @param {number} pageIndex
|
||||
* @param {PageViewport} viewport
|
||||
* @param {boolean} enhanceTextSelection
|
||||
* @returns {TextLayerBuilder}
|
||||
*/
|
||||
createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport) {
|
||||
createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport,
|
||||
enhanceTextSelection) {
|
||||
return new TextLayerBuilder({
|
||||
textLayerDiv: textLayerDiv,
|
||||
pageIndex: pageIndex,
|
||||
viewport: viewport
|
||||
viewport: viewport,
|
||||
enhanceTextSelection: enhanceTextSelection
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue