mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +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:
parent
cd22c31752
commit
fa8c0ef616
7 changed files with 76 additions and 70 deletions
|
@ -69,14 +69,27 @@ async function initPdfFindController(filename) {
|
|||
function testSearch({
|
||||
eventBus,
|
||||
pdfFindController,
|
||||
parameters,
|
||||
state,
|
||||
matchesPerPage,
|
||||
selectedMatch,
|
||||
pageMatches = null,
|
||||
pageMatchesLength = null,
|
||||
}) {
|
||||
return new Promise(function (resolve) {
|
||||
pdfFindController.executeCommand("find", parameters);
|
||||
const eventState = Object.assign(
|
||||
Object.create(null),
|
||||
{
|
||||
source: this,
|
||||
type: "",
|
||||
query: null,
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
findPrevious: false,
|
||||
},
|
||||
state
|
||||
);
|
||||
eventBus.dispatch("find", eventState);
|
||||
|
||||
// The `updatefindmatchescount` event is only emitted if the page contains
|
||||
// at least one match for the query, so the last non-zero item in the
|
||||
|
@ -142,12 +155,8 @@ describe("pdf_find_controller", function () {
|
|||
await testSearch({
|
||||
eventBus,
|
||||
pdfFindController,
|
||||
parameters: {
|
||||
state: {
|
||||
query: "Dynamic",
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
findPrevious: false,
|
||||
},
|
||||
matchesPerPage: [11, 5, 0, 3, 0, 0, 0, 1, 1, 1, 0, 3, 4, 4],
|
||||
selectedMatch: {
|
||||
|
@ -166,11 +175,8 @@ describe("pdf_find_controller", function () {
|
|||
await testSearch({
|
||||
eventBus,
|
||||
pdfFindController,
|
||||
parameters: {
|
||||
state: {
|
||||
query: "conference",
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
findPrevious: true,
|
||||
},
|
||||
matchesPerPage: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5],
|
||||
|
@ -187,12 +193,9 @@ describe("pdf_find_controller", function () {
|
|||
await testSearch({
|
||||
eventBus,
|
||||
pdfFindController,
|
||||
parameters: {
|
||||
state: {
|
||||
query: "Dynamic",
|
||||
caseSensitive: true,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
findPrevious: false,
|
||||
},
|
||||
matchesPerPage: [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3],
|
||||
selectedMatch: {
|
||||
|
@ -210,12 +213,9 @@ describe("pdf_find_controller", function () {
|
|||
await testSearch({
|
||||
eventBus,
|
||||
pdfFindController,
|
||||
parameters: {
|
||||
state: {
|
||||
query: "Government",
|
||||
caseSensitive: false,
|
||||
entireWord: true,
|
||||
phraseSearch: true,
|
||||
findPrevious: false,
|
||||
},
|
||||
matchesPerPage: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
|
||||
selectedMatch: {
|
||||
|
@ -233,12 +233,9 @@ describe("pdf_find_controller", function () {
|
|||
await testSearch({
|
||||
eventBus,
|
||||
pdfFindController,
|
||||
parameters: {
|
||||
state: {
|
||||
query: "alternate solution",
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: false,
|
||||
findPrevious: false,
|
||||
},
|
||||
matchesPerPage: [0, 0, 0, 0, 0, 1, 0, 0, 4, 0, 0, 0, 0, 0],
|
||||
selectedMatch: {
|
||||
|
@ -256,12 +253,8 @@ describe("pdf_find_controller", function () {
|
|||
await testSearch({
|
||||
eventBus,
|
||||
pdfFindController,
|
||||
parameters: {
|
||||
state: {
|
||||
query: "fraction",
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
findPrevious: false,
|
||||
},
|
||||
matchesPerPage: [3],
|
||||
selectedMatch: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue