Skip to content

Commit

Permalink
fix: Reloading causes unexpected move to the previous page
Browse files Browse the repository at this point in the history
Fixes #651
  • Loading branch information
MurakamiShinyu committed Sep 18, 2020
1 parent 309ab42 commit 8f872e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/vivliostyle/xml-doc.ts
Expand Up @@ -254,7 +254,7 @@ export class XMLDocHolder implements XmlDoc.XMLDocHolder {
node = next;
lastGood = node;
nodeOffset += (next.textContent as string).length;
if (nodeOffset > offset) {
if (nodeOffset > offset && !/^\s*$/.test(next.textContent)) {
break;
}
} else {
Expand All @@ -265,6 +265,10 @@ export class XMLDocHolder implements XmlDoc.XMLDocHolder {
}
next = node.nextSibling;
}
if (next && lastGood && /^\s*$/.test(lastGood.textContent)) {
// skip white-space text node
lastGood = next;
}
return lastGood || element;
}

Expand Down Expand Up @@ -315,7 +319,7 @@ export enum DOMParserSupportedType {
TEXT_HTML = "text/html",
TEXT_XML = "text/xml",
APPLICATION_XML = "application/xml",
APPLICATION_XHTML_XML = "application/xhtml_xml",
APPLICATION_XHTML_XML = "application/xhtml+xml",
IMAGE_SVG_XML = "image/svg+xml",
}

Expand All @@ -331,7 +335,7 @@ export function parseAndReturnNullIfError(
const parser = opt_parser || new DOMParser();
let doc: Document;
try {
doc = parser.parseFromString(str, type as SupportedType);
doc = parser.parseFromString(str, type as DOMParserSupportedType);
} catch (e) {}
if (!doc) {
return null;
Expand Down

0 comments on commit 8f872e1

Please sign in to comment.