Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…f-viewer#2524 the PDF viewer didn't scroll find matches reliably into view
  • Loading branch information
stephanrauh committed Aug 24, 2024
1 parent 726cebb commit 730abdc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
10 changes: 6 additions & 4 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ const PDFViewerApplication = {

const downloadManager = (this.downloadManager = new DownloadManager());

// #2399 modified by ngx-extended-pdf-viewer
// #2339 modified by ngx-extended-pdf-viewer
let FindControllerConstructor = PDFFindController;
if (AppOptions.get("findController")) {
FindControllerConstructor = AppOptions.get("findController");
}
// #2399 end of modification by ngx-extended-pdf-viewer
// #2339 end of modification by ngx-extended-pdf-viewer

// #2488 modified by ngx-extended-pdf-viewer
const customFindController = new FindControllerConstructor({ // #2399 modified by ngx-extended-pdf-viewer
const customFindController = new FindControllerConstructor({ // #2339 modified by ngx-extended-pdf-viewer
linkService: pdfLinkService,
eventBus,
// #492 modified by ngx-extended-pdf-viewer
Expand All @@ -437,11 +437,12 @@ const PDFViewerApplication = {
typeof PDFJSDev === "undefined"
? !window.isGECKOVIEW
: !PDFJSDev.test("GECKOVIEW"),
listenToEventBus: false,
});
this.customFindController = customFindController;
// #2488 end of modification by ngx-extended-pdf-viewer

const findController = new FindControllerConstructor({ // #2399 modified by ngx-extended-pdf-viewer
const findController = new FindControllerConstructor({ // #2339 modified by ngx-extended-pdf-viewer
linkService: pdfLinkService,
eventBus,
// #492 modified by ngx-extended-pdf-viewer
Expand All @@ -451,6 +452,7 @@ const PDFViewerApplication = {
typeof PDFJSDev === "undefined"
? !window.isGECKOVIEW
: !PDFJSDev.test("GECKOVIEW"),
listenToEventBus: true,
});
this.findController = findController;

Expand Down
14 changes: 8 additions & 6 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class PDFFindBar {
this.currentPage = options.findCurrentPageCheckbox;
this.pageRange = options.findPageRangeField;
this.caseSensitive = options.caseSensitiveCheckbox;
this.findMultipleCheckbox = options.findMultipleCheckbox;
this.matchRegExpCheckbox = options.matchRegExpCheckbox;
this.findMultipleCheckbox = options.findMultipleCheckbox; // #2509 modified by ngx-extended-pdf-viewer
this.matchRegExpCheckbox = options.matchRegExpCheckbox; // #2509 modified by ngx-extended-pdf-viewer
this.matchDiacritics = options.matchDiacriticsCheckbox;
this.entireWord = options.entireWordCheckbox;
this.findMsg = options.findMsg;
Expand Down Expand Up @@ -86,11 +86,12 @@ class PDFFindBar {
this.dispatchEvent("casesensitivitychange");
});

this.findMultipleCheckbox.addEventListener("click", () => {
// #2509 modified by ngx-extended-pdf-viewer
this.findMultipleCheckbox?.addEventListener("click", () => {
this.dispatchEvent("findmultiplechange");
});

this.matchRegExpCheckbox.addEventListener("click", () => {
this.matchRegExpCheckbox?.addEventListener("click", () => {
if (this.matchRegExpCheckbox.checked) {
this.findMultipleCheckbox.checked = false;
this.findMultipleCheckbox.disabled = true;
Expand All @@ -105,6 +106,7 @@ class PDFFindBar {
}
this.dispatchEvent("findregexpchange");
});
// #2509 end of modification by ngx-extended-pdf-viewer

this.entireWord.addEventListener("click", () => {
this.dispatchEvent("entirewordchange");
Expand All @@ -125,8 +127,8 @@ class PDFFindBar {
type,
query: this.findField.value,
caseSensitive: this.caseSensitive.checked,
findMultiple: this.findMultipleCheckbox.checked,
matchRegExp: this.matchRegExpCheckbox.checked,
findMultiple: this.findMultipleCheckbox?.checked, // #2509 modified by ngx-extended-pdf-viewer
matchRegExp: this.matchRegExpCheckbox?.checked, // #2509 modified by ngx-extended-pdf-viewer
entireWord: this.entireWord.checked,
highlightAll: this.highlightAll.checked,
findPrevious: findPrev,
Expand Down
25 changes: 18 additions & 7 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,13 @@ class PDFFindController {
/**
* @param {PDFFindControllerOptions} options
*/
constructor({ linkService, eventBus, updateMatchesCountOnProgress = true, pageViewMode }) {
constructor({
linkService,
eventBus,
updateMatchesCountOnProgress = true,
pageViewMode,
listenToEventBus, // #2339 modified by ngx-extended-pdf-viewer
}) {
this._linkService = linkService;
this._eventBus = eventBus;
this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
Expand All @@ -413,8 +419,10 @@ class PDFFindController {
this.onIsPageVisible = null;

this.#reset();
eventBus._on("find", this.#onFind.bind(this));
eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
if (listenToEventBus) { // #2339 modified by ngx-extended-pdf-viewer
eventBus._on("find", this.#onFind.bind(this));
eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
} // #2339 modified by ngx-extended-pdf-viewer
}

get highlightMatches() {
Expand Down Expand Up @@ -577,10 +585,13 @@ class PDFFindController {
// #2482 end of modification by ngx-extended-pdf-viewer
if (!this._scrollMatches || !element) {
return;
} else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
return;
} else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
return;
// #2339 modified by ngx-extended-pdf-viewer: the method is only called
// on selected matches, and since adding the customFindController, the
// index is not always correct, let's skip the check
// } else if (matchIndex===-1 || matchIndex !== this._selected.matchIdx) {
// return;
// } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
// return;
}
this._scrollMatches = false; // Ensure that scrolling only happens once.

Expand Down

0 comments on commit 730abdc

Please sign in to comment.