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

worktile / slate-angular / 914163ea-6ee0-42d0-9f61-7488a0f53348

24 Dec 2025 05:34PM UTC coverage: 37.097% (+0.03%) from 37.072%
914163ea-6ee0-42d0-9f61-7488a0f53348

push

circleci

pubuzhixing8
feat(virtual-scroll): add debugLog and move debugLog to virtual-scroll

382 of 1231 branches covered (31.03%)

Branch coverage included in aggregate %.

3 of 30 new or added lines in 2 files covered. (10.0%)

1 existing line in 1 file now uncovered.

1080 of 2710 relevant lines covered (39.85%)

24.12 hits per line

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

13.58
/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✔
NEW
17
    const doc = document;
×
NEW
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) {
×
NEW
39
            if (isDebug) {
×
NEW
40
                const height = measureHeightByElement(editor, element);
×
NEW
41
                if (height !== preHeight) {
×
NEW
42
                    debugLog(
×
43
                        'warn',
44
                        'measureHeightByElement: height not equal, index: ',
45
                        index,
46
                        'preHeight: ',
47
                        preHeight,
48
                        'height: ',
49
                        height
50
                    );
51
                }
52
            }
53
        }
54
        hasChanged = true;
×
55
        measureHeightByElement(editor, element);
×
56
    });
57
    return hasChanged;
×
58
};
59

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

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

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

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

108
    const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
×
109
    scrollTo((accumulatedHeights[anchorIndex] ?? 0) + getBusinessTop(editor));
×
110
};
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