Browse Source

Fix clear matches functionality

Julian Viereck 13 years ago
parent
commit
ecf3dae776
  1. 24
      web/viewer.js

24
web/viewer.js

@ -2254,19 +2254,12 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) {
return ret; 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) { 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 bidiTexts = this.textContent.bidiTexts;
var textDivs = this.textDivs; var textDivs = this.textDivs;
var prevEnd = null; var prevEnd = null;
@ -2274,8 +2267,6 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) {
var selectedMatchIdx = PDFFindController.selected.matchIdx; var selectedMatchIdx = PDFFindController.selected.matchIdx;
var highlightAll = PDFFindController.state.highlightAll; var highlightAll = PDFFindController.state.highlightAll;
this.clearMatches();
var infty = { var infty = {
divIdx: -1, divIdx: -1,
offset: undefined offset: undefined
@ -2377,12 +2368,13 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) {
var bidiTexts = this.textContent.bidiTexts; var bidiTexts = this.textContent.bidiTexts;
var clearedUntilDivIdx = -1; var clearedUntilDivIdx = -1;
// Clear out all current matches.
for (var i = 0; i < matches.length; i++) { for (var i = 0; i < matches.length; i++) {
var match = matches[i]; var match = matches[i];
var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx); var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
for (var n = begin; n <= match.end.divIdx; n++) { for (var n = begin; n <= match.end.divIdx; n++) {
var div = bidiTexts[n].str; var div = textDivs[n];
div.textContent = div.textContent; div.textContent = bidiTexts[n].str;
div.className = ''; div.className = '';
} }
clearedUntilDivIdx = match.end.divIdx + 1; clearedUntilDivIdx = match.end.divIdx + 1;

Loading…
Cancel
Save