slate-angular 20.2.0-next.4 → 20.2.0-next.5

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.
@@ -2579,7 +2579,7 @@ class SlateEditable {
2579
2579
  return;
2580
2580
  }
2581
2581
  if (diff.isMissingTop) {
2582
- const result = this.remeasureHeightByIndics([...diff.diffTopRenderedIndexes]);
2582
+ const result = this.remeasureHeightByIndics(diff.diffTopRenderedIndexes);
2583
2583
  if (result) {
2584
2584
  virtualView = this.refreshVirtualView();
2585
2585
  diff = this.diffVirtualView(virtualView, 'second');
@@ -2646,7 +2646,6 @@ class SlateEditable {
2646
2646
  this.renderedChildren = [];
2647
2647
  this.virtualVisibleIndexes = new Set();
2648
2648
  this.measuredHeights = new Map();
2649
- this.measurePending = false;
2650
2649
  // the height from scroll container top to editor top height element
2651
2650
  this.businessHeight = 0;
2652
2651
  this.virtualScrollInitialized = false;
@@ -2995,16 +2994,21 @@ class SlateEditable {
2995
2994
  }
2996
2995
  const elementLength = children.length;
2997
2996
  const adjustedScrollTop = Math.max(0, scrollTop - this.businessHeight);
2998
- const viewBottom = scrollTop + viewportHeight;
2997
+ const heights = children.map((_, idx) => this.getBlockHeight(idx));
2998
+ const accumulatedHeights = this.buildAccumulatedHeight(heights);
2999
+ const totalHeight = accumulatedHeights[elementLength];
3000
+ const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
3001
+ const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
3002
+ const viewBottom = limitedScrollTop + viewportHeight + this.businessHeight;
2999
3003
  let accumulatedOffset = 0;
3000
3004
  let visibleStartIndex = -1;
3001
3005
  const visible = [];
3002
3006
  const visibleIndexes = [];
3003
3007
  for (let i = 0; i < elementLength && accumulatedOffset < viewBottom; i++) {
3004
- const currentHeight = this.getBlockHeight(i);
3008
+ const currentHeight = heights[i];
3005
3009
  const nextOffset = accumulatedOffset + currentHeight;
3006
3010
  // 可视区域有交集,加入渲染
3007
- if (nextOffset > adjustedScrollTop && accumulatedOffset < viewBottom) {
3011
+ if (nextOffset > limitedScrollTop && accumulatedOffset < viewBottom) {
3008
3012
  if (visibleStartIndex === -1)
3009
3013
  visibleStartIndex = i; // 第一个相交起始位置
3010
3014
  visible.push(children[i]);
@@ -3012,11 +3016,14 @@ class SlateEditable {
3012
3016
  }
3013
3017
  accumulatedOffset = nextOffset;
3014
3018
  }
3015
- const visibleEndIndex = visibleStartIndex === -1 ? elementLength - 1 : visibleIndexes.length - 1;
3016
- const heights = children.map((_, idx) => this.getBlockHeight(idx));
3017
- const accumulatedHeights = this.buildAccumulatedHeight(heights);
3019
+ if (visibleStartIndex === -1 && elementLength) {
3020
+ visibleStartIndex = elementLength - 1;
3021
+ visible.push(children[visibleStartIndex]);
3022
+ visibleIndexes.push(visibleStartIndex);
3023
+ }
3024
+ const visibleEndIndex = visibleStartIndex === -1 ? elementLength - 1 : (visibleIndexes[visibleIndexes.length - 1] ?? visibleStartIndex);
3018
3025
  const top = visibleStartIndex === -1 ? 0 : accumulatedHeights[visibleStartIndex];
3019
- const bottom = accumulatedHeights[elementLength] - accumulatedHeights[visibleEndIndex];
3026
+ const bottom = totalHeight - accumulatedHeights[visibleEndIndex + 1];
3020
3027
  return {
3021
3028
  renderedChildren: visible.length ? visible : children,
3022
3029
  visibleIndexes: new Set(visibleIndexes),
@@ -3139,20 +3146,6 @@ class SlateEditable {
3139
3146
  }
3140
3147
  return accumulatedHeights;
3141
3148
  }
3142
- getBufferBelowHeight(viewportHeight, visibleStart, bufferCount) {
3143
- let blockHeight = 0;
3144
- let start = visibleStart;
3145
- // 循环累计高度超出视图高度代表找到向下缓冲区的起始位置
3146
- while (blockHeight < viewportHeight) {
3147
- blockHeight += this.getBlockHeight(start);
3148
- start++;
3149
- }
3150
- let bufferHeight = 0;
3151
- for (let i = start; i < start + bufferCount; i++) {
3152
- bufferHeight += this.getBlockHeight(i);
3153
- }
3154
- return bufferHeight;
3155
- }
3156
3149
  scheduleMeasureVisibleHeights() {
3157
3150
  if (!this.shouldUseVirtual()) {
3158
3151
  return;