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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.23.2 (2021-11-19)
2
+
3
+ ### Bug fixes
4
+
5
+ Avoid some unnecessary node redraws when marks are present in sibling nodes.
6
+
1
7
  ## 1.23.1 (2021-11-15)
2
8
 
3
9
  ### Bug fixes
package/dist/index.es.js CHANGED
@@ -1747,7 +1747,7 @@ var ViewTreeUpdater = function ViewTreeUpdater(top, lockedNode) {
1747
1747
  // Tracks whether anything was changed
1748
1748
  this.changed = false;
1749
1749
 
1750
- this.preMatch = preMatch(top.node.content, top.children);
1750
+ this.preMatch = preMatch(top.node.content, top);
1751
1751
  };
1752
1752
 
1753
1753
  // Destroy and remove the children between the given indices in
@@ -1808,19 +1808,16 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
1808
1808
  // Try to find a node desc matching the given data. Skip over it and
1809
1809
  // return true when successful.
1810
1810
  ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
1811
- var children = this.top.children, found = -1;
1812
- if (index >= this.preMatch.index) {
1813
- for (var i = this.index; i < children.length; i++) {
1814
- if (this.preMatch.matched.get(children[i]) == index) {
1815
- if (children[i].matchesNode(node, outerDeco, innerDeco)) { found = i; }
1816
- break
1817
- }
1818
- }
1811
+ var found = -1, targetDesc;
1812
+ if (index >= this.preMatch.index &&
1813
+ (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top &&
1814
+ targetDesc.matchesNode(node, outerDeco, innerDeco)) {
1815
+ found = this.top.children.indexOf(targetDesc, this.index);
1819
1816
  } else {
1820
- for (var i$1 = this.index, e = Math.min(children.length, i$1 + 5); i$1 < e; i$1++) {
1821
- var child = children[i$1];
1817
+ for (var i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) {
1818
+ var child = this.top.children[i];
1822
1819
  if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
1823
- found = i$1;
1820
+ found = i;
1824
1821
  break
1825
1822
  }
1826
1823
  }
@@ -1929,22 +1926,44 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
1929
1926
  }
1930
1927
  };
1931
1928
 
1932
- // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>}
1929
+ // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>, matches: ViewDesc[]}
1933
1930
  // Iterate from the end of the fragment and array of descs to find
1934
1931
  // directly matching ones, in order to avoid overeagerly reusing those
1935
1932
  // for other nodes. Returns the fragment index of the first node that
1936
1933
  // is part of the sequence of matched nodes at the end of the
1937
1934
  // fragment.
1938
- function preMatch(frag, descs) {
1939
- var fI = frag.childCount, dI = descs.length, matched = new Map;
1940
- for (; fI > 0 && dI > 0; dI--) {
1941
- var desc = descs[dI - 1], node = desc.node;
1935
+ function preMatch(frag, parentDesc) {
1936
+ var curDesc = parentDesc, descI = curDesc.children.length;
1937
+ var fI = frag.childCount, matched = new Map, matches = [];
1938
+ outer: while (fI > 0) {
1939
+ var desc = (void 0);
1940
+ for (;;) {
1941
+ if (descI) {
1942
+ var next = curDesc.children[descI - 1];
1943
+ if (next instanceof MarkViewDesc) {
1944
+ curDesc = next;
1945
+ descI = next.children.length;
1946
+ } else {
1947
+ desc = next;
1948
+ descI--;
1949
+ break
1950
+ }
1951
+ } else if (curDesc == parentDesc) {
1952
+ break outer
1953
+ } else {
1954
+ // FIXME
1955
+ descI = curDesc.parent.children.indexOf(curDesc);
1956
+ curDesc = curDesc.parent;
1957
+ }
1958
+ }
1959
+ var node = desc.node;
1942
1960
  if (!node) { continue }
1943
1961
  if (node != frag.child(fI - 1)) { break }
1944
1962
  --fI;
1945
1963
  matched.set(desc, fI);
1964
+ matches.push(desc);
1946
1965
  }
1947
- return {index: fI, matched: matched}
1966
+ return {index: fI, matched: matched, matches: matches.reverse()}
1948
1967
  }
1949
1968
 
1950
1969
  function compareSide(a, b) { return a.type.side - b.type.side }