Skip to content

Commit

Permalink
Simplify and fix position tracking in parseRange
Browse files Browse the repository at this point in the history
FIX: Fix an issue where the DOM change handler would treat the parsed
content as the wrong part of the document.
  • Loading branch information
marijnh committed Jun 12, 2019
1 parent ad82ca8 commit 379a5f7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/viewdesc.js
Expand Up @@ -270,16 +270,16 @@ class ViewDesc {
return {node: this.contentDOM, from, to, fromOffset: 0, toOffset: this.contentDOM.childNodes.length}

let fromOffset = -1, toOffset = -1
for (let offset = 0, i = 0;; i++) {
for (let offset = base, i = 0;; i++) {
let child = this.children[i], end = offset + child.size
if (fromOffset == -1 && from <= end) {
let childBase = offset + child.border
// FIXME maybe descend mark views to parse a narrower range?
if (from >= childBase && to <= end - child.border && child.node &&
child.contentDOM && this.contentDOM.contains(child.contentDOM))
return child.parseRange(from - childBase, to - childBase, base + childBase)
return child.parseRange(from, to, childBase)

from = base + offset
from = offset
for (let j = i; j > 0; j--) {
let prev = this.children[j - 1]
if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) {
Expand All @@ -291,7 +291,7 @@ class ViewDesc {
if (fromOffset == -1) fromOffset = 0
}
if (fromOffset > -1 && to <= end) {
to = base + end
to = end
for (let j = i + 1; j < this.children.length; j++) {
let next = this.children[j]
if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) {
Expand Down

0 comments on commit 379a5f7

Please sign in to comment.