1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

[api-minor] Change PDFFindController to use the "find"-event directly (issue 12731)

Looking at the code, I do have to agree with the point made in issue 12731 about it being unexpected/unhelpful that the `PDFFindController.executeCommand`-method isn't directly usable with the "find"-event.
The reason for it being this way is, as so often, for historical reasons: The `executeCommand`-method was added (just) prior to the introduction of the `EventBus` in the viewer.

Obviously we cannot simply change the existing `PDFFindController.executeCommand`-method, since that'd be a breaking change in code which has existed for over five years.
Initially I figured that we could simply add a new method in `PDFFindController` that'd accept the state from the "find"-event, however after thinking about this and looking through the use-cases in the default viewer I settled on a slightly different approach: Let the `PDFFindController` just listen for the "find"-event (on the `EventBus`-instance) directly instead, which also removes one level of (unneeded) indirection during searching in the default viewer.

For GENERIC builds of the PDF.js library, the old `PDFFindController.executeCommand`-method is still available with a deprecation warning.
This commit is contained in:
Jonas Jenwald 2021-10-03 16:03:51 +02:00
parent cd22c31752
commit fa8c0ef616
7 changed files with 76 additions and 70 deletions

View file

@ -77,7 +77,11 @@ eventBus.on("pagesinit", function () {
// We can try searching for things.
if (SEARCH_FOR) {
pdfFindController.executeCommand("find", { query: SEARCH_FOR });
if (!pdfFindController._onFind) {
pdfFindController.executeCommand("find", { query: SEARCH_FOR });
} else {
eventBus.dispatch("find", { type: "", query: SEARCH_FOR });
}
}
});