From 890c567eca9e08b338aaa7f91ef7467354547760 Mon Sep 17 00:00:00 2001 From: bootleq Date: Thu, 20 Jun 2024 16:24:45 +0800 Subject: [PATCH] Expose entireWord in updateFindControlState Allow apps with supportsIntegratedFind to better monitor the find state. A recognized use case is the Firefox findbar, its "not found" sound must consider `entireWord` and only make noise when it is off. See related implementation in https://hg.mozilla.org/mozilla-central/rev/16b902cbcf26 This change can help if we have to move the implementation from cpp to jsm. --- test/unit/pdf_find_controller_spec.js | 32 +++++++++++++++++++++++++++ web/app.js | 2 ++ web/pdf_find_controller.js | 1 + 3 files changed, 35 insertions(+) diff --git a/test/unit/pdf_find_controller_spec.js b/test/unit/pdf_find_controller_spec.js index b89316e5b806b..e455d5048c58f 100644 --- a/test/unit/pdf_find_controller_spec.js +++ b/test/unit/pdf_find_controller_spec.js @@ -1022,4 +1022,36 @@ describe("pdf_find_controller", function () { pageMatchesLength: [[1, 1, 1, 1, 1, 1, 1, 1, 1]], }); }); + + it("dispatches updatefindcontrolstate with correct properties", async function () { + const testOnFind = ({ eventBus }) => + new Promise(function (resolve) { + const eventState = { + source: this, + type: "", + query: "Foo", + caseSensitive: true, + entireWord: true, + findPrevious: false, + matchDiacritics: false, + }; + eventBus.dispatch("find", eventState); + + eventBus.on("updatefindcontrolstate", function (evt) { + expect(evt).toEqual( + jasmine.objectContaining({ + state: FindState.NOT_FOUND, + previous: false, + entireWord: true, + matchesCount: { current: 0, total: 0 }, + rawQuery: "Foo", + }) + ); + resolve(); + }); + }); + + const { eventBus } = await initPdfFindController(); + await testOnFind({ eventBus }); + }); }); diff --git a/web/app.js b/web/app.js index 58e6e798e5776..891b2aa218d15 100644 --- a/web/app.js +++ b/web/app.js @@ -2516,6 +2516,7 @@ function webViewerUpdateFindMatchesCount({ matchesCount }) { function webViewerUpdateFindControlState({ state, previous, + entireWord, matchesCount, rawQuery, }) { @@ -2523,6 +2524,7 @@ function webViewerUpdateFindControlState({ PDFViewerApplication.externalServices.updateFindControlState({ result: state, findPrevious: previous, + entireWord, matchesCount, rawQuery, }); diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 8b9f3d9aeda13..3990b2eb6668f 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -1133,6 +1133,7 @@ class PDFFindController { source: this, state, previous, + entireWord: this.#state?.entireWord ?? null, matchesCount: this.#requestMatchesCount(), rawQuery: this.#state?.query ?? null, });