From 3f850033cb69ce2f02cc903cc03dc30450c4d40a Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Wed, 4 Nov 2015 12:08:28 -0600 Subject: [PATCH] Adjusts endOfContent location to be in the middle of selection --- web/text_layer_builder.css | 6 +++++- web/text_layer_builder.js | 41 +++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/web/text_layer_builder.css b/web/text_layer_builder.css index 1bfc1b8c22bb5e..4d0c4568b4dbe2 100644 --- a/web/text_layer_builder.css +++ b/web/text_layer_builder.css @@ -66,7 +66,7 @@ display: block; position: absolute; left: 0; - top: 0; + top: 100%; right: 0px; bottom: 0px; z-index: -1; @@ -75,3 +75,7 @@ -ms-user-select: none; -moz-user-select: none; } + +.textLayer .endOfContent.active { + top: 0px; +} diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index c50f256a0d032f..b9e3aa4df20599 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -51,6 +51,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() { this.viewport = options.viewport; this.textDivs = []; this.findController = options.findController || null; + this._bindMouse(); } TextLayerBuilder.prototype = { @@ -396,7 +397,45 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() { this.matches = this.convertMatches(this.findController === null ? [] : (this.findController.pageMatches[this.pageIdx] || [])); this.renderMatches(this.matches); - } + }, + + /** + * Fixes text selection: adds additional div where mouse was clicked. + * This reduces flickering of the content if mouse slowly dragged down/up. + * @private + */ + _bindMouse: function () { + var div = this.textLayerDiv; + div.addEventListener('mousedown', function (e) { + var end = div.querySelector('.endOfContent'); + if (!end) { + return; + } +//#if !(MOZCENTRAL || FIREFOX) + var adjustTop = true; +//#if GENERIC + adjustTop = window.getComputedStyle(end). + getPropertyValue('-moz-user-select') !== 'none'; +//#endif + if (adjustTop) { + var divBounds = div.getBoundingClientRect(); + var r = Math.max(0, (e.pageY - divBounds.top) / divBounds.height); + end.style.top = (r * 100).toFixed(2) + '%'; + } +//#endif + end.classList.add('active'); + }); + div.addEventListener('mouseup', function (e) { + var end = div.querySelector('.endOfContent'); + if (!end) { + return; + } +//#if !(MOZCENTRAL || FIREFOX) + end.style.top = ''; +//#endif + end.classList.remove('active'); + }); + }, }; return TextLayerBuilder; })();