Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly compute the mapping between text and normalized text when it contains a compound word on two lines #19122

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,4 @@
!bug1922766.pdf
!issue18956.pdf
!issue19083.pdf
!issue19120.pdf
Binary file added test/pdfs/issue19120.pdf
Binary file not shown.
28 changes: 25 additions & 3 deletions test/unit/pdf_find_controller_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,23 +1062,45 @@ describe("pdf_find_controller", function () {
await testOnFind({ eventBus });
});

it("performs a search in a text with compound word on two lines", async function () {
it("performs a search in a text with a compound word on two lines", async function () {
const { eventBus, pdfFindController } =
await initPdfFindController("issue18693.pdf");

const query = "hel-Lo";
await testSearch({
eventBus,
pdfFindController,
state: {
query: "hel-Lo",
query,
},
matchesPerPage: [1],
selectedMatch: {
pageIndex: 0,
matchIndex: 0,
},
pageMatches: [[6]],
pageMatchesLength: [[7]],
pageMatchesLength: [[query.length]],
});
});

it("performs a search after a compound word on two lines", async function () {
const { eventBus, pdfFindController } =
await initPdfFindController("issue19120.pdf");

const query = "a";
await testSearch({
eventBus,
pdfFindController,
state: {
query,
},
matchesPerPage: [3],
selectedMatch: {
pageIndex: 0,
matchIndex: 0,
},
pageMatches: [[0, 4, 15]],
pageMatchesLength: [[query.length, query.length, query.length]],
});
});

Expand Down
3 changes: 1 addition & 2 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ function normalize(text) {

if (p5) {
// Compound word with a line break after the hyphen.
positions.push([i - shift + 3, 1 + shift]);
shift += 1;
// Since the \n isn't in the original text, o = 3 and n = 3.
shiftOrigin += 1;
eol += 1;
return p5.replace("\n", "");
Expand Down