• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

worktile / slate-angular / e12a82c2-be1b-4727-8ffe-5b3725c83934

25 Dec 2025 07:42AM UTC coverage: 37.088% (-0.009%) from 37.097%
e12a82c2-be1b-4727-8ffe-5b3725c83934

push

circleci

pubuzhixing8
feat(virtual-scroll): fix min-height was reset issue

382 of 1231 branches covered (31.03%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

1080 of 2711 relevant lines covered (39.84%)

24.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

13.41
/packages/src/utils/virtual-scroll.ts
1
import { Element } from 'slate';
2
import { AngularEditor } from '../plugins/angular-editor';
3
import { SLATE_DEBUG_KEY, SLATE_DEBUG_KEY_SCROLL_TOP, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT } from './environment';
4
import { ELEMENT_TO_COMPONENT } from './weak-maps';
5
import { BaseElementComponent } from '../view/base';
6
import { BaseElementFlavour } from '../view/flavour/element';
7
import { VirtualScrollDebugOverlay } from '../components/editable/debug';
8

9
export const isDebug = localStorage.getItem(SLATE_DEBUG_KEY) === 'true';
1✔
10
export const isDebugScrollTop = localStorage.getItem(SLATE_DEBUG_KEY_SCROLL_TOP) === 'true';
1✔
11

12
export const ELEMENT_KEY_TO_HEIGHTS = new WeakMap<AngularEditor, Map<string, number>>();
1✔
13

14
export const EDITOR_TO_BUSINESS_TOP = new WeakMap<AngularEditor, number>();
1✔
15

16
export const debugLog = (type: 'log' | 'warn', ...args: any[]) => {
1✔
17
    const doc = document;
×
18
    VirtualScrollDebugOverlay.log(doc, type, ...args);
×
19
};
20

21
export const measureHeightByElement = (editor: AngularEditor, element: Element) => {
1✔
22
    const key = AngularEditor.findKey(editor, element);
×
23
    const view = ELEMENT_TO_COMPONENT.get(element);
×
24
    if (!view) {
×
25
        return;
×
26
    }
27
    const ret = (view as BaseElementComponent | BaseElementFlavour).getRealHeight();
×
28
    const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
×
29
    heights.set(key.id, ret as number);
×
30
    return ret as number;
×
31
};
32

33
export const measureHeightByIndics = (editor: AngularEditor, indics: number[], force = false) => {
1!
34
    let hasChanged = false;
×
35
    indics.forEach((index, i) => {
×
36
        const element = editor.children[index] as Element;
×
37
        const preHeight = getRealHeightByElement(editor, element, 0);
×
38
        if (preHeight && !force) {
×
39
            if (isDebug) {
×
40
                const height = measureHeightByElement(editor, element);
×
41
                if (height !== preHeight) {
×
42
                    debugLog(
×
43
                        'warn',
44
                        'measureHeightByElement: height not equal, index: ',
45
                        index,
46
                        'preHeight: ',
47
                        preHeight,
48
                        'height: ',
49
                        height
50
                    );
51
                }
52
            }
NEW
53
            return;
×
54
        }
55
        hasChanged = true;
×
56
        measureHeightByElement(editor, element);
×
57
    });
58
    return hasChanged;
×
59
};
60

61
export const getBusinessTop = (editor: AngularEditor) => {
1✔
62
    return EDITOR_TO_BUSINESS_TOP.get(editor) ?? 0;
×
63
};
64

65
export const getRealHeightByElement = (
1✔
66
    editor: AngularEditor,
67
    element: Element,
68
    defaultHeight: number = VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT
×
69
) => {
70
    const isVisible = editor.isVisible(element);
×
71
    if (!isVisible) {
×
72
        return 0;
×
73
    }
74
    const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
×
75
    const key = AngularEditor.findKey(editor, element);
×
76
    const height = heights?.get(key.id);
×
77
    if (typeof height === 'number') {
×
78
        return height;
×
79
    }
80
    if (heights?.has(key.id)) {
×
81
        console.error('getBlockHeight: invalid height value', key.id, height);
×
82
    }
83
    return defaultHeight;
×
84
};
85

86
export const buildHeightsAndAccumulatedHeights = (editor: AngularEditor) => {
1✔
87
    const children = (editor.children || []) as Element[];
×
88
    const heights = new Array(children.length);
×
89
    const accumulatedHeights = new Array(children.length + 1);
×
90
    accumulatedHeights[0] = 0;
×
91
    for (let i = 0; i < children.length; i++) {
×
92
        const height = getRealHeightByElement(editor, children[i]);
×
93
        heights[i] = height;
×
94
        accumulatedHeights[i + 1] = accumulatedHeights[i] + height;
×
95
    }
96
    return { heights, accumulatedHeights };
×
97
};
98

99
export const scrollToElement = (editor: AngularEditor, element: Element, scrollTo: (scrollTop: number) => void) => {
1✔
100
    const children = editor.children;
×
101
    if (!children.length) {
×
102
        return;
×
103
    }
104
    const anchorIndex = children.findIndex(item => item === element);
×
105
    if (anchorIndex < 0) {
×
106
        return;
×
107
    }
108

109
    const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
×
110
    scrollTo((accumulatedHeights[anchorIndex] ?? 0) + getBusinessTop(editor));
×
111
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc