|
@@ -4139,8 +4139,39 @@ var PDFFindController = function () {
|
|
|
});
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'normalize',
|
|
|
- value: function normalize(text) {
|
|
|
+ key: 'executeCommand',
|
|
|
+ value: function executeCommand(cmd, state) {
|
|
|
+ var _this2 = this;
|
|
|
+
|
|
|
+ if (this.state === null || cmd !== 'findagain') {
|
|
|
+ this.dirtyMatch = true;
|
|
|
+ }
|
|
|
+ this.state = state;
|
|
|
+ this._updateUIState(FindState.PENDING);
|
|
|
+ this._firstPagePromise.then(function () {
|
|
|
+ _this2._extractText();
|
|
|
+ clearTimeout(_this2.findTimeout);
|
|
|
+ if (cmd === 'find') {
|
|
|
+ _this2.findTimeout = setTimeout(_this2._nextMatch.bind(_this2), FIND_TIMEOUT);
|
|
|
+ } else {
|
|
|
+ _this2._nextMatch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'updateMatchPosition',
|
|
|
+ value: function updateMatchPosition(pageIndex, matchIndex, elements, beginIdx) {
|
|
|
+ if (this.selected.matchIdx === matchIndex && this.selected.pageIdx === pageIndex) {
|
|
|
+ var spot = {
|
|
|
+ top: FIND_SCROLL_OFFSET_TOP,
|
|
|
+ left: FIND_SCROLL_OFFSET_LEFT
|
|
|
+ };
|
|
|
+ (0, _ui_utils.scrollIntoView)(elements[beginIdx], spot, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_normalize',
|
|
|
+ value: function _normalize(text) {
|
|
|
return text.replace(this.normalizationRegex, function (ch) {
|
|
|
return CHARACTERS_TO_NORMALIZE[ch];
|
|
|
});
|
|
@@ -4182,8 +4213,8 @@ var PDFFindController = function () {
|
|
|
}
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'calcFindPhraseMatch',
|
|
|
- value: function calcFindPhraseMatch(query, pageIndex, pageContent) {
|
|
|
+ key: '_calculatePhraseMatch',
|
|
|
+ value: function _calculatePhraseMatch(query, pageIndex, pageContent) {
|
|
|
var matches = [];
|
|
|
var queryLen = query.length;
|
|
|
var matchIdx = -queryLen;
|
|
@@ -4197,8 +4228,8 @@ var PDFFindController = function () {
|
|
|
this.pageMatches[pageIndex] = matches;
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'calcFindWordMatch',
|
|
|
- value: function calcFindWordMatch(query, pageIndex, pageContent) {
|
|
|
+ key: '_calculateWordMatch',
|
|
|
+ value: function _calculateWordMatch(query, pageIndex, pageContent) {
|
|
|
var matchesWithLength = [];
|
|
|
var queryArray = query.match(/\S+/g);
|
|
|
for (var i = 0, len = queryArray.length; i < len; i++) {
|
|
@@ -4225,10 +4256,10 @@ var PDFFindController = function () {
|
|
|
this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]);
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'calcFindMatch',
|
|
|
- value: function calcFindMatch(pageIndex) {
|
|
|
- var pageContent = this.normalize(this.pageContents[pageIndex]);
|
|
|
- var query = this.normalize(this.state.query);
|
|
|
+ key: '_calculateMatch',
|
|
|
+ value: function _calculateMatch(pageIndex) {
|
|
|
+ var pageContent = this._normalize(this.pageContents[pageIndex]);
|
|
|
+ var query = this._normalize(this.state.query);
|
|
|
var caseSensitive = this.state.caseSensitive;
|
|
|
var phraseSearch = this.state.phraseSearch;
|
|
|
var queryLen = query.length;
|
|
@@ -4240,24 +4271,24 @@ var PDFFindController = function () {
|
|
|
query = query.toLowerCase();
|
|
|
}
|
|
|
if (phraseSearch) {
|
|
|
- this.calcFindPhraseMatch(query, pageIndex, pageContent);
|
|
|
+ this._calculatePhraseMatch(query, pageIndex, pageContent);
|
|
|
} else {
|
|
|
- this.calcFindWordMatch(query, pageIndex, pageContent);
|
|
|
+ this._calculateWordMatch(query, pageIndex, pageContent);
|
|
|
}
|
|
|
- this.updatePage(pageIndex);
|
|
|
+ this._updatePage(pageIndex);
|
|
|
if (this.resumePageIdx === pageIndex) {
|
|
|
this.resumePageIdx = null;
|
|
|
- this.nextPageMatch();
|
|
|
+ this._nextPageMatch();
|
|
|
}
|
|
|
if (this.pageMatches[pageIndex].length > 0) {
|
|
|
this.matchCount += this.pageMatches[pageIndex].length;
|
|
|
- this.updateUIResultsCount();
|
|
|
+ this._updateUIResultsCount();
|
|
|
}
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'extractText',
|
|
|
- value: function extractText() {
|
|
|
- var _this2 = this;
|
|
|
+ key: '_extractText',
|
|
|
+ value: function _extractText() {
|
|
|
+ var _this3 = this;
|
|
|
|
|
|
if (this.startedTextExtraction) {
|
|
|
return;
|
|
@@ -4268,19 +4299,19 @@ var PDFFindController = function () {
|
|
|
|
|
|
var _loop = function _loop(i, ii) {
|
|
|
var extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
|
|
|
- _this2.extractTextPromises[i] = extractTextCapability.promise;
|
|
|
+ _this3.extractTextPromises[i] = extractTextCapability.promise;
|
|
|
promise = promise.then(function () {
|
|
|
- return _this2.pdfViewer.getPageTextContent(i).then(function (textContent) {
|
|
|
+ return _this3.pdfViewer.getPageTextContent(i).then(function (textContent) {
|
|
|
var textItems = textContent.items;
|
|
|
var strBuf = [];
|
|
|
for (var j = 0, jj = textItems.length; j < jj; j++) {
|
|
|
strBuf.push(textItems[j].str);
|
|
|
}
|
|
|
- _this2.pageContents[i] = strBuf.join('');
|
|
|
+ _this3.pageContents[i] = strBuf.join('');
|
|
|
extractTextCapability.resolve(i);
|
|
|
}, function (reason) {
|
|
|
console.error('Unable to get page ' + (i + 1) + ' text content', reason);
|
|
|
- _this2.pageContents[i] = '';
|
|
|
+ _this3.pageContents[i] = '';
|
|
|
extractTextCapability.resolve(i);
|
|
|
});
|
|
|
});
|
|
@@ -4291,28 +4322,8 @@ var PDFFindController = function () {
|
|
|
}
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'executeCommand',
|
|
|
- value: function executeCommand(cmd, state) {
|
|
|
- var _this3 = this;
|
|
|
-
|
|
|
- if (this.state === null || cmd !== 'findagain') {
|
|
|
- this.dirtyMatch = true;
|
|
|
- }
|
|
|
- this.state = state;
|
|
|
- this.updateUIState(FindState.PENDING);
|
|
|
- this._firstPagePromise.then(function () {
|
|
|
- _this3.extractText();
|
|
|
- clearTimeout(_this3.findTimeout);
|
|
|
- if (cmd === 'find') {
|
|
|
- _this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), FIND_TIMEOUT);
|
|
|
- } else {
|
|
|
- _this3.nextMatch();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'updatePage',
|
|
|
- value: function updatePage(index) {
|
|
|
+ key: '_updatePage',
|
|
|
+ value: function _updatePage(index) {
|
|
|
if (this.selected.pageIdx === index) {
|
|
|
this.pdfViewer.currentPageNumber = index + 1;
|
|
|
}
|
|
@@ -4322,8 +4333,8 @@ var PDFFindController = function () {
|
|
|
}
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'nextMatch',
|
|
|
- value: function nextMatch() {
|
|
|
+ key: '_nextMatch',
|
|
|
+ value: function _nextMatch() {
|
|
|
var _this4 = this;
|
|
|
|
|
|
var previous = this.state.findPrevious;
|
|
@@ -4341,18 +4352,18 @@ var PDFFindController = function () {
|
|
|
this.matchCount = 0;
|
|
|
this.pageMatchesLength = null;
|
|
|
for (var i = 0; i < numPages; i++) {
|
|
|
- this.updatePage(i);
|
|
|
+ this._updatePage(i);
|
|
|
if (!(i in this.pendingFindMatches)) {
|
|
|
this.pendingFindMatches[i] = true;
|
|
|
this.extractTextPromises[i].then(function (pageIdx) {
|
|
|
delete _this4.pendingFindMatches[pageIdx];
|
|
|
- _this4.calcFindMatch(pageIdx);
|
|
|
+ _this4._calculateMatch(pageIdx);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (this.state.query === '') {
|
|
|
- this.updateUIState(FindState.FOUND);
|
|
|
+ this._updateUIState(FindState.FOUND);
|
|
|
return;
|
|
|
}
|
|
|
if (this.resumePageIdx) {
|
|
@@ -4365,49 +4376,38 @@ var PDFFindController = function () {
|
|
|
if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
|
|
|
this.hadMatch = true;
|
|
|
offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
|
|
|
- this.updateMatch(true);
|
|
|
+ this._updateMatch(true);
|
|
|
return;
|
|
|
}
|
|
|
- this.advanceOffsetPage(previous);
|
|
|
+ this._advanceOffsetPage(previous);
|
|
|
}
|
|
|
- this.nextPageMatch();
|
|
|
+ this._nextPageMatch();
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'matchesReady',
|
|
|
- value: function matchesReady(matches) {
|
|
|
+ key: '_matchesReady',
|
|
|
+ value: function _matchesReady(matches) {
|
|
|
var offset = this.offset;
|
|
|
var numMatches = matches.length;
|
|
|
var previous = this.state.findPrevious;
|
|
|
if (numMatches) {
|
|
|
this.hadMatch = true;
|
|
|
offset.matchIdx = previous ? numMatches - 1 : 0;
|
|
|
- this.updateMatch(true);
|
|
|
+ this._updateMatch(true);
|
|
|
return true;
|
|
|
}
|
|
|
- this.advanceOffsetPage(previous);
|
|
|
+ this._advanceOffsetPage(previous);
|
|
|
if (offset.wrapped) {
|
|
|
offset.matchIdx = null;
|
|
|
if (this.pagesToSearch < 0) {
|
|
|
- this.updateMatch(false);
|
|
|
+ this._updateMatch(false);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'updateMatchPosition',
|
|
|
- value: function updateMatchPosition(pageIndex, matchIndex, elements, beginIdx) {
|
|
|
- if (this.selected.matchIdx === matchIndex && this.selected.pageIdx === pageIndex) {
|
|
|
- var spot = {
|
|
|
- top: FIND_SCROLL_OFFSET_TOP,
|
|
|
- left: FIND_SCROLL_OFFSET_LEFT
|
|
|
- };
|
|
|
- (0, _ui_utils.scrollIntoView)(elements[beginIdx], spot, true);
|
|
|
- }
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'nextPageMatch',
|
|
|
- value: function nextPageMatch() {
|
|
|
+ key: '_nextPageMatch',
|
|
|
+ value: function _nextPageMatch() {
|
|
|
if (this.resumePageIdx !== null) {
|
|
|
console.error('There can only be one pending page.');
|
|
|
}
|
|
@@ -4419,11 +4419,11 @@ var PDFFindController = function () {
|
|
|
this.resumePageIdx = pageIdx;
|
|
|
break;
|
|
|
}
|
|
|
- } while (!this.matchesReady(matches));
|
|
|
+ } while (!this._matchesReady(matches));
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'advanceOffsetPage',
|
|
|
- value: function advanceOffsetPage(previous) {
|
|
|
+ key: '_advanceOffsetPage',
|
|
|
+ value: function _advanceOffsetPage(previous) {
|
|
|
var offset = this.offset;
|
|
|
var numPages = this.extractTextPromises.length;
|
|
|
offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
|
|
@@ -4435,8 +4435,8 @@ var PDFFindController = function () {
|
|
|
}
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'updateMatch',
|
|
|
- value: function updateMatch() {
|
|
|
+ key: '_updateMatch',
|
|
|
+ value: function _updateMatch() {
|
|
|
var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
|
|
|
var state = FindState.NOT_FOUND;
|
|
@@ -4448,24 +4448,24 @@ var PDFFindController = function () {
|
|
|
this.selected.matchIdx = this.offset.matchIdx;
|
|
|
state = wrapped ? FindState.WRAPPED : FindState.FOUND;
|
|
|
if (previousPage !== -1 && previousPage !== this.selected.pageIdx) {
|
|
|
- this.updatePage(previousPage);
|
|
|
+ this._updatePage(previousPage);
|
|
|
}
|
|
|
}
|
|
|
- this.updateUIState(state, this.state.findPrevious);
|
|
|
+ this._updateUIState(state, this.state.findPrevious);
|
|
|
if (this.selected.pageIdx !== -1) {
|
|
|
- this.updatePage(this.selected.pageIdx);
|
|
|
+ this._updatePage(this.selected.pageIdx);
|
|
|
}
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'updateUIResultsCount',
|
|
|
- value: function updateUIResultsCount() {
|
|
|
+ key: '_updateUIResultsCount',
|
|
|
+ value: function _updateUIResultsCount() {
|
|
|
if (this.onUpdateResultsCount) {
|
|
|
this.onUpdateResultsCount(this.matchCount);
|
|
|
}
|
|
|
}
|
|
|
}, {
|
|
|
- key: 'updateUIState',
|
|
|
- value: function updateUIState(state, previous) {
|
|
|
+ key: '_updateUIState',
|
|
|
+ value: function _updateUIState(state, previous) {
|
|
|
if (this.onUpdateState) {
|
|
|
this.onUpdateState(state, previous, this.matchCount);
|
|
|
}
|