From ecf3dae7764990a0f0e7218541a7609fc61338bc Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Fri, 28 Sep 2012 15:16:10 +0200 Subject: [PATCH] Fix clear matches functionality --- web/viewer.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index f55074263..1883333a5 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -2254,19 +2254,12 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) { return ret; }; - this.clearMatches = function textLayerBuilder_clearMatches() { - var textDivs = this.textDivs; - - // Clear all previous highlights - textDivs.forEach(function(div) { - var spans = div.querySelectorAll('span'); - for (var i = 0, ii = spans.length; i < ii; i++) { - spans[i].className = ''; - } - }); - } - this.renderMatches = function textLayerBuilder_renderMatches(matches) { + // Early exit if there is nothing to render. + if (matches.length === 0) { + return; + } + var bidiTexts = this.textContent.bidiTexts; var textDivs = this.textDivs; var prevEnd = null; @@ -2274,8 +2267,6 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) { var selectedMatchIdx = PDFFindController.selected.matchIdx; var highlightAll = PDFFindController.state.highlightAll; - this.clearMatches(); - var infty = { divIdx: -1, offset: undefined @@ -2377,12 +2368,13 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) { var bidiTexts = this.textContent.bidiTexts; var clearedUntilDivIdx = -1; + // Clear out all current matches. for (var i = 0; i < matches.length; i++) { var match = matches[i]; var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx); for (var n = begin; n <= match.end.divIdx; n++) { - var div = bidiTexts[n].str; - div.textContent = div.textContent; + var div = textDivs[n]; + div.textContent = bidiTexts[n].str; div.className = ''; } clearedUntilDivIdx = match.end.divIdx + 1;