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

Potential fix for wrong page being displayed sometimes. #914

Merged
merged 4 commits into from
Jun 5, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Started checking for end of word.
  • Loading branch information
Tushar Dudani authored and Tushar Dudani committed Feb 11, 2019
commit 8399af32f545b0f0f6be7cd8567cac7008b81bd7
29 changes: 18 additions & 11 deletions src/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,19 +574,26 @@ class Contents {

if(this.epubcfi.isCfiString(target)) {
let range = new EpubCFI(target).toRange(this.document, ignoreClass);
try {
if (!range.endContainer) {
// If the end for the range is not set, it results in collapsed becoming
// true. This in turn leads to inconsistent behaviour when calling
// getBoundingRect. Wrong bounds lead to the wrong page being displayed.
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15684911/
range.setEnd(range.startContainer, range.startContainer.textContent.length);
}
} catch (e) {
console.error("setting end offset to start container length failed", e);
}

if(range) {
try {
if (!range.endContainer ||
(range.startContainer == range.endContainer
&& range.startOffset == range.endOffset)) {
// If the end for the range is not set, it results in collapsed becoming
// true. This in turn leads to inconsistent behaviour when calling
// getBoundingRect. Wrong bounds lead to the wrong page being displayed.
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15684911/
let pos = range.startContainer.textContent.indexOf(" ", range.startOffset);
if (pos == -1) {
pos = range.startContainer.textContent.length;
}
range.setEnd(range.startContainer, pos);
}
} catch (e) {
console.error("setting end offset to start container length failed", e);
}

if (range.startContainer.nodeType === Node.ELEMENT_NODE) {
position = range.startContainer.getBoundingClientRect();
targetPos.left = position.left;
Expand Down