Merge pull request #15947 from calixteman/gv_dont_update_find
[GV] Avoid to update the finder when the results aren't complete
This commit is contained in:
commit
7b95788248
@ -85,7 +85,8 @@ function testSearch({
|
|||||||
selectedMatch,
|
selectedMatch,
|
||||||
pageMatches = null,
|
pageMatches = null,
|
||||||
pageMatchesLength = null,
|
pageMatchesLength = null,
|
||||||
countUpdate = null,
|
updateFindMatchesCount = null,
|
||||||
|
updateFindControlState = null,
|
||||||
}) {
|
}) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
const eventState = Object.assign(
|
const eventState = Object.assign(
|
||||||
@ -127,11 +128,20 @@ function testSearch({
|
|||||||
return a + b;
|
return a + b;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (updateFindControlState) {
|
||||||
|
eventBus.on(
|
||||||
|
"updatefindcontrolstate",
|
||||||
|
function onUpdateFindControlState(evt) {
|
||||||
|
updateFindControlState[0] += 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
eventBus.on(
|
eventBus.on(
|
||||||
"updatefindmatchescount",
|
"updatefindmatchescount",
|
||||||
function onUpdateFindMatchesCount(evt) {
|
function onUpdateFindMatchesCount(evt) {
|
||||||
if (countUpdate) {
|
if (updateFindMatchesCount) {
|
||||||
countUpdate[0] += 1;
|
updateFindMatchesCount[0] += 1;
|
||||||
}
|
}
|
||||||
if (pdfFindController.pageMatches.length !== totalPages) {
|
if (pdfFindController.pageMatches.length !== totalPages) {
|
||||||
return;
|
return;
|
||||||
@ -199,7 +209,7 @@ function testEmptySearch({ eventBus, pdfFindController, state }) {
|
|||||||
describe("pdf_find_controller", function () {
|
describe("pdf_find_controller", function () {
|
||||||
it("performs a normal search", async function () {
|
it("performs a normal search", async function () {
|
||||||
const { eventBus, pdfFindController } = await initPdfFindController();
|
const { eventBus, pdfFindController } = await initPdfFindController();
|
||||||
const countUpdate = [0];
|
const updateFindMatchesCount = [0];
|
||||||
|
|
||||||
await testSearch({
|
await testSearch({
|
||||||
eventBus,
|
eventBus,
|
||||||
@ -212,10 +222,10 @@ describe("pdf_find_controller", function () {
|
|||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
matchIndex: 0,
|
matchIndex: 0,
|
||||||
},
|
},
|
||||||
countUpdate,
|
updateFindMatchesCount,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(countUpdate[0]).toBe(9);
|
expect(updateFindMatchesCount[0]).toBe(9);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("performs a normal search but the total counts is only updated one time", async function () {
|
it("performs a normal search but the total counts is only updated one time", async function () {
|
||||||
@ -223,7 +233,8 @@ describe("pdf_find_controller", function () {
|
|||||||
null,
|
null,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
const countUpdate = [0];
|
const updateFindMatchesCount = [0];
|
||||||
|
const updateFindControlState = [0];
|
||||||
|
|
||||||
await testSearch({
|
await testSearch({
|
||||||
eventBus,
|
eventBus,
|
||||||
@ -236,10 +247,12 @@ describe("pdf_find_controller", function () {
|
|||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
matchIndex: 0,
|
matchIndex: 0,
|
||||||
},
|
},
|
||||||
countUpdate,
|
updateFindMatchesCount,
|
||||||
|
updateFindControlState,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(countUpdate[0]).toBe(1);
|
expect(updateFindMatchesCount[0]).toBe(1);
|
||||||
|
expect(updateFindControlState[0]).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("performs a normal search and finds the previous result", async function () {
|
it("performs a normal search and finds the previous result", async function () {
|
||||||
|
@ -1052,6 +1052,16 @@ class PDFFindController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#updateUIState(state, previous = false) {
|
#updateUIState(state, previous = false) {
|
||||||
|
if (
|
||||||
|
!this.#updateMatchesCountOnProgress &&
|
||||||
|
(this.#visitedPagesCount !== this._linkService.pagesCount ||
|
||||||
|
state === FindState.PENDING)
|
||||||
|
) {
|
||||||
|
// When this.#updateMatchesCountOnProgress is false we only send an update
|
||||||
|
// when everything is ready.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._eventBus.dispatch("updatefindcontrolstate", {
|
this._eventBus.dispatch("updatefindcontrolstate", {
|
||||||
source: this,
|
source: this,
|
||||||
state,
|
state,
|
||||||
|
Loading…
Reference in New Issue
Block a user