Display the index of the currently active search result in the matches counter of the findbar (issue 6993, bug 1062025)
For the `PDFFindBar` implementation, similar to the native Firefox findbar, the matches count displayed is now limited to a (hopefully) reasonable value. *Please note:* In order to enable this feature in the `MOZCENTRAL` version, a follow-up patch will be required once this has landed in `mozilla-central`.
This commit is contained in:
parent
510f1c84d2
commit
c9a2564882
@ -167,6 +167,13 @@ find_highlight=Highlight all
|
|||||||
find_match_case_label=Match case
|
find_match_case_label=Match case
|
||||||
find_reached_top=Reached top of document, continued from bottom
|
find_reached_top=Reached top of document, continued from bottom
|
||||||
find_reached_bottom=Reached end of document, continued from top
|
find_reached_bottom=Reached end of document, continued from top
|
||||||
|
# LOCALIZATION NOTE (find_matches_count): "{{current}}" and "{{total}}" will be
|
||||||
|
# replaced by a number representing the index of the currently active find result,
|
||||||
|
# respectively a number representing the total number of matches in the document.
|
||||||
|
find_matches_count={{current}} of {{total}} matches
|
||||||
|
# LOCALIZATION NOTE (find_matches_count_limit): "{{limit}}" will be replaced by
|
||||||
|
# a numerical value.
|
||||||
|
find_matches_count_limit=More than {{limit}} matches
|
||||||
find_not_found=Phrase not found
|
find_not_found=Phrase not found
|
||||||
|
|
||||||
# Error panel labels
|
# Error panel labels
|
||||||
|
@ -167,6 +167,13 @@ find_highlight=Markera alla
|
|||||||
find_match_case_label=Matcha versal/gemen
|
find_match_case_label=Matcha versal/gemen
|
||||||
find_reached_top=Nådde början av dokumentet, började från slutet
|
find_reached_top=Nådde början av dokumentet, började från slutet
|
||||||
find_reached_bottom=Nådde slutet på dokumentet, började från början
|
find_reached_bottom=Nådde slutet på dokumentet, började från början
|
||||||
|
# LOCALIZATION NOTE (find_matches_count): "{{current}}" and "{{total}}" will be
|
||||||
|
# replaced by a number representing the index of the currently active find result,
|
||||||
|
# respectively a number representing the total number of matches in the document.
|
||||||
|
find_matches_count={{current}} av {{total}} matchande
|
||||||
|
# LOCALIZATION NOTE (find_matches_count_limit): "{{limit}}" will be replaced by
|
||||||
|
# a numerical value.
|
||||||
|
find_matches_count_limit=Fler än {{limit}} matchningar
|
||||||
find_not_found=Frasen hittades inte
|
find_not_found=Frasen hittades inte
|
||||||
|
|
||||||
# Error panel labels
|
# Error panel labels
|
||||||
|
13
web/app.js
13
web/app.js
@ -54,6 +54,7 @@ const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
|
|||||||
|
|
||||||
const DefaultExternalServices = {
|
const DefaultExternalServices = {
|
||||||
updateFindControlState(data) {},
|
updateFindControlState(data) {},
|
||||||
|
updateFindMatchesCount(data) {},
|
||||||
initPassiveLoading(callbacks) {},
|
initPassiveLoading(callbacks) {},
|
||||||
fallback(data, callback) {},
|
fallback(data, callback) {},
|
||||||
reportTelemetry(data) {},
|
reportTelemetry(data) {},
|
||||||
@ -345,20 +346,22 @@ let PDFViewerApplication = {
|
|||||||
pdfViewer: this.pdfViewer,
|
pdfViewer: this.pdfViewer,
|
||||||
eventBus,
|
eventBus,
|
||||||
});
|
});
|
||||||
this.findController.onUpdateResultsCount = (matchCount) => {
|
this.findController.onUpdateResultsCount = (matchesCount) => {
|
||||||
if (this.supportsIntegratedFind) {
|
if (this.supportsIntegratedFind) {
|
||||||
return;
|
this.externalServices.updateFindMatchesCount(matchesCount);
|
||||||
|
} else {
|
||||||
|
this.findBar.updateResultsCount(matchesCount);
|
||||||
}
|
}
|
||||||
this.findBar.updateResultsCount(matchCount);
|
|
||||||
};
|
};
|
||||||
this.findController.onUpdateState = (state, previous, matchCount) => {
|
this.findController.onUpdateState = (state, previous, matchesCount) => {
|
||||||
if (this.supportsIntegratedFind) {
|
if (this.supportsIntegratedFind) {
|
||||||
this.externalServices.updateFindControlState({
|
this.externalServices.updateFindControlState({
|
||||||
result: state,
|
result: state,
|
||||||
findPrevious: previous,
|
findPrevious: previous,
|
||||||
|
matchesCount,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.findBar.updateUIState(state, previous, matchCount);
|
this.findBar.updateUIState(state, previous, matchesCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,6 +209,10 @@ PDFViewerApplication.externalServices = {
|
|||||||
FirefoxCom.request('updateFindControlState', data);
|
FirefoxCom.request('updateFindControlState', data);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateFindMatchesCount(data) {
|
||||||
|
// FirefoxCom.request('updateFindMatchesCount', data);
|
||||||
|
},
|
||||||
|
|
||||||
initPassiveLoading(callbacks) {
|
initPassiveLoading(callbacks) {
|
||||||
let pdfDataRangeTransport;
|
let pdfDataRangeTransport;
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
import { FindState } from './pdf_find_controller';
|
import { FindState } from './pdf_find_controller';
|
||||||
import { NullL10n } from './ui_utils';
|
import { NullL10n } from './ui_utils';
|
||||||
|
|
||||||
|
const MATCHES_COUNT_LIMIT = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a "search bar" given a set of DOM elements that act as controls
|
* Creates a "search bar" given a set of DOM elements that act as controls
|
||||||
* for searching or for setting search preferences in the UI. This object
|
* for searching or for setting search preferences in the UI. This object
|
||||||
@ -102,7 +104,7 @@ class PDFFindBar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUIState(state, previous, matchCount) {
|
updateUIState(state, previous, matchesCount) {
|
||||||
let notFound = false;
|
let notFound = false;
|
||||||
let findMsg = '';
|
let findMsg = '';
|
||||||
let status = '';
|
let status = '';
|
||||||
@ -143,26 +145,34 @@ class PDFFindBar {
|
|||||||
this._adjustWidth();
|
this._adjustWidth();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.updateResultsCount(matchCount);
|
this.updateResultsCount(matchesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResultsCount(matchCount) {
|
updateResultsCount({ current, total, }) {
|
||||||
if (!this.findResultsCount) {
|
if (!this.findResultsCount) {
|
||||||
return; // No UI control is provided.
|
return; // No UI control is provided.
|
||||||
}
|
}
|
||||||
|
let matchesCountMsg = '';
|
||||||
|
|
||||||
if (!matchCount) {
|
if (total) {
|
||||||
// If there are no matches, hide and reset the counter.
|
if (total > MATCHES_COUNT_LIMIT) {
|
||||||
this.findResultsCount.classList.add('hidden');
|
matchesCountMsg = this.l10n.get('find_matches_count_limit', {
|
||||||
this.findResultsCount.textContent = '';
|
limit: MATCHES_COUNT_LIMIT.toLocaleString(),
|
||||||
} else {
|
}, 'More than {{limit}} matches');
|
||||||
// Update and show the match counter.
|
} else {
|
||||||
this.findResultsCount.textContent = matchCount.toLocaleString();
|
matchesCountMsg = this.l10n.get('find_matches_count', {
|
||||||
this.findResultsCount.classList.remove('hidden');
|
current: current.toLocaleString(),
|
||||||
|
total: total.toLocaleString(),
|
||||||
|
}, '{{current}} of {{total}} matches');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Since `updateResultsCount` may be called from `PDFFindController`,
|
Promise.resolve(matchesCountMsg).then((msg) => {
|
||||||
// ensure that the width of the findbar is always updated correctly.
|
this.findResultsCount.textContent = msg;
|
||||||
this._adjustWidth();
|
this.findResultsCount.classList[!total ? 'add' : 'remove']('hidden');
|
||||||
|
// Since `updateResultsCount` may be called from `PDFFindController`,
|
||||||
|
// ensure that the width of the findbar is always updated correctly.
|
||||||
|
this._adjustWidth();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
|
@ -68,7 +68,7 @@ class PDFFindController {
|
|||||||
this.pageContents = []; // Stores the text for each page.
|
this.pageContents = []; // Stores the text for each page.
|
||||||
this.pageMatches = [];
|
this.pageMatches = [];
|
||||||
this.pageMatchesLength = null;
|
this.pageMatchesLength = null;
|
||||||
this.matchCount = 0;
|
this.matchesCountTotal = 0;
|
||||||
this.selected = { // Currently selected match.
|
this.selected = { // Currently selected match.
|
||||||
pageIdx: -1,
|
pageIdx: -1,
|
||||||
matchIdx: -1,
|
matchIdx: -1,
|
||||||
@ -269,8 +269,9 @@ class PDFFindController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the match count.
|
// Update the match count.
|
||||||
if (this.pageMatches[pageIndex].length > 0) {
|
const pageMatchesCount = this.pageMatches[pageIndex].length;
|
||||||
this.matchCount += this.pageMatches[pageIndex].length;
|
if (pageMatchesCount > 0) {
|
||||||
|
this.matchesCountTotal += pageMatchesCount;
|
||||||
this._updateUIResultsCount();
|
this._updateUIResultsCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,7 +339,7 @@ class PDFFindController {
|
|||||||
this.hadMatch = false;
|
this.hadMatch = false;
|
||||||
this.resumePageIdx = null;
|
this.resumePageIdx = null;
|
||||||
this.pageMatches = [];
|
this.pageMatches = [];
|
||||||
this.matchCount = 0;
|
this.matchesCountTotal = 0;
|
||||||
this.pageMatchesLength = null;
|
this.pageMatchesLength = null;
|
||||||
|
|
||||||
for (let i = 0; i < numPages; i++) {
|
for (let i = 0; i < numPages; i++) {
|
||||||
@ -475,16 +476,32 @@ class PDFFindController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateUIResultsCount() {
|
_requestMatchesCount() {
|
||||||
if (this.onUpdateResultsCount) {
|
const { pageIdx, matchIdx, } = this.selected;
|
||||||
this.onUpdateResultsCount(this.matchCount);
|
let current = 0;
|
||||||
|
if (matchIdx !== -1) {
|
||||||
|
for (let i = 0; i < pageIdx; i++) {
|
||||||
|
current += (this.pageMatches[i] && this.pageMatches[i].length) || 0;
|
||||||
|
}
|
||||||
|
current += matchIdx + 1;
|
||||||
}
|
}
|
||||||
|
return { current, total: this.matchesCountTotal, };
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateUIResultsCount() {
|
||||||
|
if (!this.onUpdateResultsCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const matchesCount = this._requestMatchesCount();
|
||||||
|
this.onUpdateResultsCount(matchesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateUIState(state, previous) {
|
_updateUIState(state, previous) {
|
||||||
if (this.onUpdateState) {
|
if (!this.onUpdateState) {
|
||||||
this.onUpdateState(state, previous, this.matchCount);
|
return;
|
||||||
}
|
}
|
||||||
|
const matchesCount = this._requestMatchesCount();
|
||||||
|
this.onUpdateState(state, previous, matchesCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,10 +109,10 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
||||||
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
||||||
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
||||||
<span id="findResultsCount" class="toolbarLabel hidden"></span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="findbarMessageContainer">
|
<div id="findbarMessageContainer">
|
||||||
|
<span id="findResultsCount" class="toolbarLabel hidden"></span>
|
||||||
<span id="findMsg" class="toolbarLabel"></span>
|
<span id="findMsg" class="toolbarLabel"></span>
|
||||||
</div>
|
</div>
|
||||||
</div> <!-- findbar -->
|
</div> <!-- findbar -->
|
||||||
|
Loading…
Reference in New Issue
Block a user