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

glideapps / glide-data-grid / 7455656024

09 Jan 2024 01:59AM CUT coverage: 92.126% (+5.7%) from 86.42%
7455656024

Pull #810

github

jassmith
Fix jitter with freeze rows. Still inefficient
Pull Request #810: 6.0.0

2722 of 3335 branches covered (0.0%)

16509 of 17920 relevant lines covered (92.13%)

3197.67 hits per line

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

80.56
/packages/core/src/data-editor/use-cells-for-selection.ts
1
import * as React from "react";
1✔
2
import type { DataGridSearchProps } from "../internal/data-grid-search/data-grid-search.js";
1✔
3
import { type CellArray, type GridCell, GridCellKind } from "../internal/data-grid/data-grid-types.js";
1✔
4
import type { DataEditorProps } from "./data-editor.js";
1✔
5

1✔
6
type CellsForSelectionCallback = NonNullable<DataGridSearchProps["getCellsForSelection"]>;
1✔
7
export function useCellsForSelection(
1✔
8
    getCellsForSelectionIn: CellsForSelectionCallback | true | undefined,
724✔
9
    getCellContent: DataEditorProps["getCellContent"],
724✔
10
    rowMarkerOffset: number,
724✔
11
    abortController: AbortController,
724✔
12
    rows: number
724✔
13
) {
724✔
14
    const getCellsForSelectionDirectWhenValid = React.useCallback<CellsForSelectionCallback>(
724✔
15
        rect => {
724✔
16
            if (getCellsForSelectionIn === true) {
175✔
17
                const result: GridCell[][] = [];
175✔
18

175✔
19
                for (let y = rect.y; y < rect.y + rect.height; y++) {
175✔
20
                    const row: GridCell[] = [];
9,328✔
21
                    for (let x = rect.x; x < rect.x + rect.width; x++) {
9,328✔
22
                        if (x < 0 || y >= rows) {
19,392✔
23
                            row.push({
13✔
24
                                kind: GridCellKind.Loading,
13✔
25
                                allowOverlay: false,
13✔
26
                            });
13✔
27
                        } else {
19,392✔
28
                            row.push(getCellContent([x, y]));
19,379✔
29
                        }
19,379✔
30
                    }
19,392✔
31
                    result.push(row);
9,328✔
32
                }
9,328✔
33

175✔
34
                return result;
175✔
35
            }
175!
36
            return getCellsForSelectionIn?.(rect, abortController.signal) ?? [];
175!
37
        },
175✔
38
        [abortController.signal, getCellContent, getCellsForSelectionIn, rows]
724✔
39
    );
724✔
40
    const getCellsForSelectionDirect =
724✔
41
        getCellsForSelectionIn !== undefined ? getCellsForSelectionDirectWhenValid : undefined;
724!
42
    const getCellsForSelectionMangled = React.useCallback<CellsForSelectionCallback>(
724✔
43
        rect => {
724✔
44
            if (getCellsForSelectionDirect === undefined) return [];
175!
45
            const newRect = {
175✔
46
                ...rect,
175✔
47
                x: rect.x - rowMarkerOffset,
175✔
48
            };
175✔
49
            if (newRect.x < 0) {
175!
50
                newRect.x = 0;
×
51
                newRect.width--;
×
52
                const r = getCellsForSelectionDirect(newRect, abortController.signal);
×
53

×
54
                if (typeof r === "function") {
×
55
                    return async () =>
×
56
                        // eslint-disable-next-line unicorn/no-await-expression-member
×
57
                        (await r()).map<CellArray[0]>(row => [
×
58
                            { kind: GridCellKind.Loading, allowOverlay: false },
×
59
                            ...row,
×
60
                        ]);
×
61
                }
×
62
                return r.map(row => [{ kind: GridCellKind.Loading, allowOverlay: false }, ...row]);
×
63
            }
×
64
            return getCellsForSelectionDirect(newRect, abortController.signal);
175✔
65
        },
175✔
66
        [abortController.signal, getCellsForSelectionDirect, rowMarkerOffset]
724✔
67
    );
724✔
68

724✔
69
    const getCellsForSelection = getCellsForSelectionIn !== undefined ? getCellsForSelectionMangled : undefined;
724!
70

724✔
71
    return [getCellsForSelection, getCellsForSelectionDirect] as const;
724✔
72
}
724✔
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

© 2025 Coveralls, Inc