prosemirror-view 1.23.1 → 1.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1751,7 +1751,7 @@ var ViewTreeUpdater = function ViewTreeUpdater(top, lockedNode) {
1751
1751
  // Tracks whether anything was changed
1752
1752
  this.changed = false;
1753
1753
 
1754
- this.preMatch = preMatch(top.node.content, top.children);
1754
+ this.preMatch = preMatch(top.node.content, top);
1755
1755
  };
1756
1756
 
1757
1757
  // Destroy and remove the children between the given indices in
@@ -1812,19 +1812,16 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
1812
1812
  // Try to find a node desc matching the given data. Skip over it and
1813
1813
  // return true when successful.
1814
1814
  ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
1815
- var children = this.top.children, found = -1;
1816
- if (index >= this.preMatch.index) {
1817
- for (var i = this.index; i < children.length; i++) {
1818
- if (this.preMatch.matched.get(children[i]) == index) {
1819
- if (children[i].matchesNode(node, outerDeco, innerDeco)) { found = i; }
1820
- break
1821
- }
1822
- }
1815
+ var found = -1, targetDesc;
1816
+ if (index >= this.preMatch.index &&
1817
+ (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top &&
1818
+ targetDesc.matchesNode(node, outerDeco, innerDeco)) {
1819
+ found = this.top.children.indexOf(targetDesc, this.index);
1823
1820
  } else {
1824
- for (var i$1 = this.index, e = Math.min(children.length, i$1 + 5); i$1 < e; i$1++) {
1825
- var child = children[i$1];
1821
+ for (var i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) {
1822
+ var child = this.top.children[i];
1826
1823
  if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
1827
- found = i$1;
1824
+ found = i;
1828
1825
  break
1829
1826
  }
1830
1827
  }
@@ -1933,22 +1930,44 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
1933
1930
  }
1934
1931
  };
1935
1932
 
1936
- // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>}
1933
+ // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>, matches: ViewDesc[]}
1937
1934
  // Iterate from the end of the fragment and array of descs to find
1938
1935
  // directly matching ones, in order to avoid overeagerly reusing those
1939
1936
  // for other nodes. Returns the fragment index of the first node that
1940
1937
  // is part of the sequence of matched nodes at the end of the
1941
1938
  // fragment.
1942
- function preMatch(frag, descs) {
1943
- var fI = frag.childCount, dI = descs.length, matched = new Map;
1944
- for (; fI > 0 && dI > 0; dI--) {
1945
- var desc = descs[dI - 1], node = desc.node;
1939
+ function preMatch(frag, parentDesc) {
1940
+ var curDesc = parentDesc, descI = curDesc.children.length;
1941
+ var fI = frag.childCount, matched = new Map, matches = [];
1942
+ outer: while (fI > 0) {
1943
+ var desc = (void 0);
1944
+ for (;;) {
1945
+ if (descI) {
1946
+ var next = curDesc.children[descI - 1];
1947
+ if (next instanceof MarkViewDesc) {
1948
+ curDesc = next;
1949
+ descI = next.children.length;
1950
+ } else {
1951
+ desc = next;
1952
+ descI--;
1953
+ break
1954
+ }
1955
+ } else if (curDesc == parentDesc) {
1956
+ break outer
1957
+ } else {
1958
+ // FIXME
1959
+ descI = curDesc.parent.children.indexOf(curDesc);
1960
+ curDesc = curDesc.parent;
1961
+ }
1962
+ }
1963
+ var node = desc.node;
1946
1964
  if (!node) { continue }
1947
1965
  if (node != frag.child(fI - 1)) { break }
1948
1966
  --fI;
1949
1967
  matched.set(desc, fI);
1968
+ matches.push(desc);
1950
1969
  }
1951
- return {index: fI, matched: matched}
1970
+ return {index: fI, matched: matched, matches: matches.reverse()}
1952
1971
  }
1953
1972
 
1954
1973
  function compareSide(a, b) { return a.type.side - b.type.side }