mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
[api-minor] Highlight search results correctly for normalized text (PR 9448)
This patch is a rebased *and* refactored version of PR 9448, such that it applies cleanly given that `PDFFindController` has changed since that PR was opened; obviously keeping the original author information intact. This patch will thus ensure that e.g. fractions, and other things that we normalize before searching, will still be highlighted correctly in the textLayer. Furthermore, this patch also adds basic unit-tests for this functionality. *Note:* The `[api-minor]` tag is added, since third-party implementations of the `PDFFindController` must now always use the `pageMatchesLength` property to get accurate length information (see the `web/text_layer_builder.js` changes). Co-authored-by: Ross Johnson <ross@mazira.com> Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>
This commit is contained in:
parent
1de1ae0be6
commit
6dae2677d5
6 changed files with 220 additions and 106 deletions
|
@ -161,12 +161,11 @@ class TextLayerBuilder {
|
|||
if (!matches) {
|
||||
return [];
|
||||
}
|
||||
const { findController, textContentItemsStr } = this;
|
||||
const { textContentItemsStr } = this;
|
||||
|
||||
let i = 0,
|
||||
iIndex = 0;
|
||||
const end = textContentItemsStr.length - 1;
|
||||
const queryLen = findController.state.query.length;
|
||||
const result = [];
|
||||
|
||||
for (let m = 0, mm = matches.length; m < mm; m++) {
|
||||
|
@ -191,13 +190,7 @@ class TextLayerBuilder {
|
|||
};
|
||||
|
||||
// Calculate the end position.
|
||||
if (matchesLength) {
|
||||
// Multiterm search.
|
||||
matchIdx += matchesLength[m];
|
||||
} else {
|
||||
// Phrase search.
|
||||
matchIdx += queryLen;
|
||||
}
|
||||
matchIdx += matchesLength[m];
|
||||
|
||||
// Somewhat the same array as above, but use > instead of >= to get
|
||||
// the end position right.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue