1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

Started checking for end of word.

This commit is contained in:
Tushar Dudani 2019-02-11 22:11:37 +05:30
parent 3a0f10195b
commit 8399af32f5

View file

@ -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;