Commit 904810bd authored by Robert Knight's avatar Robert Knight

Refactor `strippedHint` initialization

Combine two separate if blocks into one.
parent 7f4de8c4
...@@ -387,10 +387,12 @@ async function anchorQuote(quoteSelector, positionHint) { ...@@ -387,10 +387,12 @@ async function anchorQuote(quoteSelector, positionHint) {
let bestMatch; let bestMatch;
for (let page of pageIndexes) { for (let page of pageIndexes) {
const text = await getPageTextContent(page); const text = await getPageTextContent(page);
const [strippedText, offsets] = stripSpaces(text);
// Expected offset of quote in current page based on position hint. // Determine expected offset of quote in current page based on position hint.
let hint; let strippedHint;
if (expectedPageIndex !== undefined) { if (expectedPageIndex !== undefined && expectedOffsetInPage !== undefined) {
let hint;
if (page < expectedPageIndex) { if (page < expectedPageIndex) {
hint = text.length; // Prefer matches closer to end of page. hint = text.length; // Prefer matches closer to end of page.
} else if (page === expectedPageIndex) { } else if (page === expectedPageIndex) {
...@@ -398,13 +400,8 @@ async function anchorQuote(quoteSelector, positionHint) { ...@@ -398,13 +400,8 @@ async function anchorQuote(quoteSelector, positionHint) {
} else { } else {
hint = 0; // Prefer matches closer to start of page. hint = 0; // Prefer matches closer to start of page.
} }
}
const [strippedText, offsets] = stripSpaces(text); // Convert expected offset in original text into offset into stripped text.
// Convert expected offset in original text into offset into stripped text.
let strippedHint;
if (hint !== undefined) {
strippedHint = 0; strippedHint = 0;
while (strippedHint < offsets.length && offsets[strippedHint] < hint) { while (strippedHint < offsets.length && offsets[strippedHint] < hint) {
++strippedHint; ++strippedHint;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment