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

glideapps / glide-data-grid / 9021282036

09 May 2024 05:44PM CUT coverage: 91.291%. Remained the same
9021282036

Pull #951

github

jeremyll
Fix scrolling by pixels
Pull Request #951: Fix scrolling by pixels

2888 of 3576 branches covered (80.76%)

2 of 2 new or added lines in 1 file covered. (100.0%)

17778 of 19474 relevant lines covered (91.29%)

3114.64 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,
725✔
9
    getCellContent: DataEditorProps["getCellContent"],
725✔
10
    rowMarkerOffset: number,
725✔
11
    abortController: AbortController,
725✔
12
    rows: number
725✔
13
) {
725✔
14
    const getCellsForSelectionDirectWhenValid = React.useCallback<CellsForSelectionCallback>(
725✔
15
        rect => {
725✔
16
            if (getCellsForSelectionIn === true) {
171✔
17
                const result: GridCell[][] = [];
171✔
18

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

171✔
34
                return result;
171✔
35
            }
171!
36
            return getCellsForSelectionIn?.(rect, abortController.signal) ?? [];
171!
37
        },
171✔
38
        [abortController.signal, getCellContent, getCellsForSelectionIn, rows]
725✔
39
    );
725✔
40
    const getCellsForSelectionDirect =
725✔
41
        getCellsForSelectionIn !== undefined ? getCellsForSelectionDirectWhenValid : undefined;
725!
42
    const getCellsForSelectionMangled = React.useCallback<CellsForSelectionCallback>(
725✔
43
        rect => {
725✔
44
            if (getCellsForSelectionDirect === undefined) return [];
171!
45
            const newRect = {
171✔
46
                ...rect,
171✔
47
                x: rect.x - rowMarkerOffset,
171✔
48
            };
171✔
49
            if (newRect.x < 0) {
171!
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);
171✔
65
        },
171✔
66
        [abortController.signal, getCellsForSelectionDirect, rowMarkerOffset]
725✔
67
    );
725✔
68

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

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