Skip to content

Commit

Permalink
Merge pull request #4 from analyst-one/hypercubed-make-find-controlle…
Browse files Browse the repository at this point in the history
…r-methods-public

Make find controller methods public
  • Loading branch information
stephanrauh committed May 24, 2024
1 parent 92c6d3f commit ab1e907
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
import { binarySearchFirstItem, scrollIntoView } from "./ui_utils.js";
import { getCharacterType, getNormalizeWithNFKC } from "./pdf_find_utils.js";

/**
* Search and replacements for ngx-extended-pdf-viewer
*
* `#convertToRegExpString` -> `_convertToRegExpString`
* `#calculateMatch` -> `_calculateMatch`
* `#calculateRegExpMatch` -> `_calculateRegExpMatch`
*
*/

const FindState = {
FOUND: 0,
NOT_FOUND: 1,
Expand Down Expand Up @@ -679,7 +688,7 @@ class PDFFindController {
return true;
}

#calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
_calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
const matches = (this._pageMatches[pageIndex] = []);
const matchesLength = (this._pageMatchesLength[pageIndex] = []);
if (!query) {
Expand Down Expand Up @@ -710,7 +719,7 @@ class PDFFindController {
}
}

#convertToRegExpString(query, hasDiacritics) {
_convertToRegExpString(query, hasDiacritics) {
const { matchDiacritics } = this.#state;
let isUnicode = false;
query = query.replaceAll(
Expand Down Expand Up @@ -780,7 +789,7 @@ class PDFFindController {
return [isUnicode, query];
}

#calculateMatch(pageIndex) {
_calculateMatch(pageIndex) {
let query = this.#query;
if (query.length === 0) {
return; // Do nothing: the matches should be wiped out already.
Expand All @@ -791,15 +800,15 @@ class PDFFindController {

let isUnicode = false;
if (typeof query === "string") {
[isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
[isUnicode, query] = this._convertToRegExpString(query, hasDiacritics);
} else {
// Words are sorted in reverse order to be sure that "foobar" is matched
// before "foo" in case the query is "foobar foo".
query = query
.sort()
.reverse()
.map(q => {
const [isUnicodePart, queryPart] = this.#convertToRegExpString(
const [isUnicodePart, queryPart] = this._convertToRegExpString(
q,
hasDiacritics
);
Expand All @@ -812,7 +821,7 @@ class PDFFindController {
const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
query = query ? new RegExp(query, flags) : null;

this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
this._calculateRegExpMatch(query, entireWord, pageIndex, pageContent);

// When `highlightAll` is set, ensure that the matches on previously
// rendered (and still active) pages are correctly highlighted.
Expand Down Expand Up @@ -941,7 +950,7 @@ class PDFFindController {
this._pendingFindMatches.add(i);
this._extractTextPromises[i].then(() => {
this._pendingFindMatches.delete(i);
this.#calculateMatch(i);
this._calculateMatch(i);
});
}
}
Expand Down

0 comments on commit ab1e907

Please sign in to comment.