Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(databases): extend a cell range with Shift+Arrow (#9391)

Wolf Mermelsteinadc93c989465
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index bc94b5b2fa..b76d22204b 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -242,7 +242,8 @@ Then trigger the interaction and read `window.__inst.log`. `'1,2,3' → '' → '
Remote database selections have a backend-free desktop/phone regression that
measures every row and cell while collaborators move, share a cell, or select a
range, and checks their name labels above the header and under it once
-scrolled: `just test-database-browser`. Keep the outline an overlay, never a
+scrolled, and keyboard (Shift+Arrow) ranges whose moving corner stays in
+view: `just test-database-browser`. Keep the outline an overlay, never a
border on the cell. Virtual rows are transformed, so each is its own stacking
context: a row carrying labels rises above the header only while its top edge
is in view.
diff --git a/apps/web/src/features/database/browser-test/grid.tsx b/apps/web/src/features/database/browser-test/grid.tsx
index 3703be99db..85e998bda0 100644
--- a/apps/web/src/features/database/browser-test/grid.tsx
+++ b/apps/web/src/features/database/browser-test/grid.tsx
@@ -29,7 +29,11 @@ const COLUMNS: DatabaseViewColumn[] = [
{ ...title, id: 'owner', name: 'Owner' },
{ ...title, id: 'notes', name: 'Notes' },
];
-const ROWS: DatabaseRow[] = Array.from({ length: 30 }, (_, index) => ({
+// `?rows=` grows the table past what the virtualizer mounts.
+const ROW_COUNT = Number(
+ new URLSearchParams(location.search).get('rows') ?? 30
+);
+const ROWS: DatabaseRow[] = Array.from({ length: ROW_COUNT }, (_, index) => ({
rowId: `row-${index}`,
cells: {
title: `Task ${index + 1}`,
diff --git a/apps/web/src/features/database/browser-test/keyboard-range.browser.e2e.ts b/apps/web/src/features/database/browser-test/keyboard-range.browser.e2e.ts
new file mode 100644
index 0000000000..35fd9d1d6d
--- /dev/null
+++ b/apps/web/src/features/database/browser-test/keyboard-range.browser.e2e.ts
@@ -0,0 +1,121 @@
+import { expect, type Page, test } from '@playwright/test';
+
+async function open(page: Page, rows = 30) {
+ await page.goto(`/src/features/database/browser-test/grid.html?rows=${rows}`);
+ await expect(page.getByRole('grid', { name: 'Tasks' })).toBeVisible();
+ await page.evaluate(() => document.fonts.ready);
+}
+
+function cell(page: Page, rowId: string, column: number) {
+ return page.locator(
+ `[data-grid-row-id="${rowId}"] [data-grid-cell][data-grid-column="${column}"]`
+ );
+}
+
+function selected(page: Page) {
+ return page.evaluate(() =>
+ [...document.querySelectorAll<HTMLElement>('[aria-selected="true"]')].map(
+ (element) =>
+ `${element.closest<HTMLElement>('[data-grid-row-id]')!.dataset.gridRowId}:${element.dataset.gridColumn}`
+ )
+ );
+}
+
+/** Whether the element's center is on screen, below the sticky header and above the summary. */
+function inView(page: Page, rowId: string, column: number) {
+ return cell(page, rowId, column).evaluate((element) => {
+ const { x, y, width, height } = element.getBoundingClientRect();
+ const hit = document.elementFromPoint(x + width / 2, y + height / 2);
+ return !!hit && element.contains(hit);
+ });
+}
+
+test('Shift+Arrow grows and shrinks a range and keeps its moving corner in view', async ({
+ page,
+}, testInfo) => {
+ await page.setViewportSize({ width: 1280, height: 800 });
+ await open(page);
+ await cell(page, 'row-1', 1).focus();
+
+ await page.keyboard.press('Shift+ArrowRight');
+ await page.keyboard.press('Shift+ArrowDown');
+ await page.keyboard.press('Shift+ArrowDown');
+ expect(await selected(page)).toEqual([
+ 'row-1:1',
+ 'row-1:2',
+ 'row-2:1',
+ 'row-2:2',
+ 'row-3:1',
+ 'row-3:2',
+ ]);
+ await page.screenshot({ path: testInfo.outputPath('keyboard-range.png') });
+
+ await page.keyboard.press('Shift+ArrowUp');
+ expect(await selected(page)).toHaveLength(4);
+
+ // Down to the last row, far below the fold.
+ await page.keyboard.press('Shift+ControlOrMeta+ArrowDown');
+ expect(await selected(page)).toHaveLength(29 * 2);
+ await expect.poll(() => inView(page, 'row-29', 2)).toBe(true);
+
+ // A plain arrow collapses it.
+ await page.keyboard.press('ArrowUp');
+ expect(await selected(page)).toEqual([]);
+});
+
+test('Shift+Cmd/Ctrl+Arrow reaches and scrolls to a row the virtualizer had not mounted', async ({
+ page,
+}) => {
+ await page.setViewportSize({ width: 1280, height: 800 });
+ await open(page, 300);
+ await expect(cell(page, 'row-299', 1)).toHaveCount(0);
+ await cell(page, 'row-0', 1).focus();
+
+ await page.keyboard.press('Shift+ControlOrMeta+ArrowDown');
+
+ await expect.poll(() => inView(page, 'row-299', 1)).toBe(true);
+ await expect(cell(page, 'row-299', 1)).toHaveAttribute(
+ 'aria-selected',
+ 'true'
+ );
+ await expect
+ .poll(() =>
+ page.evaluate(
+ () =>
+ !!document.activeElement?.closest(
+ '[data-grid-row-id="row-299"] [data-grid-column="1"]'
+ )
+ )
+ )
+ .toBe(true);
+ await page.keyboard.press('Shift+ArrowUp');
+ await expect(cell(page, 'row-299', 1)).toHaveAttribute(
+ 'aria-selected',
+ 'false'
+ );
+});
+
+test('a collaborator’s range is drawn with the presence ring', async ({
+ page,
+}, testInfo) => {
+ await page.setViewportSize({ width: 1280, height: 800 });
+ await open(page);
+ await page.evaluate(() =>
+ Reflect.get(
+ window,
+ 'setRemoteUsers'
+ )([
+ {
+ userId: 'macro|[email protected]',
+ rowId: 'row-1',
+ columnId: 'title',
+ endRowId: 'row-3',
+ endColumnId: 'owner',
+ editing: false,
+ },
+ ])
+ );
+ await expect(page.getByRole('note', { name: 'Alex is here' })).toBeVisible();
+ await expect(page.locator('[data-remote-outline]')).toHaveCount(6);
+ await page.screenshot({ path: testInfo.outputPath('remote-range.png') });
+});
diff --git a/apps/web/src/features/database/components/database-table.test.tsx b/apps/web/src/features/database/components/database-table.test.tsx
index 25e5787fb2..309a8afb75 100644
--- a/apps/web/src/features/database/components/database-table.test.tsx
+++ b/apps/web/src/features/database/components/database-table.test.tsx
@@ -1131,3 +1131,130 @@ it.each(['Delete', 'Backspace'])(
);
}
);
+
+describe('keyboard ranges', () => {
+ const cell = (rowId: string, column: number) =>
+ document.querySelector<HTMLElement>(
+ `[data-grid-row-id="${rowId}"] [data-grid-column="${column}"]`
+ )!;
+ const press = (key: string, init: KeyboardEventInit = {}) =>
+ fireEvent.keyDown(document.activeElement!, { key, ...init });
+ const selected = () =>
+ [...document.querySelectorAll<HTMLElement>('[aria-selected="true"]')].map(
+ (element) =>
+ `${element.closest<HTMLElement>('[data-grid-row-id]')!.dataset.gridRowId}:${element.dataset.gridColumn}`
+ );
+
+ it('grows and shrinks with Shift+Arrow, sharing the range as it changes, and clears it with Delete', async () => {
+ const { onClearCells, onCellFocus, onWrite } = setup();
+ cell('one', 1).focus();
+
+ press('ArrowRight', { shiftKey: true });
+ expect(selected()).toEqual(['one:1', 'one:2']);
+ expect(onCellFocus).toHaveBeenLastCalledWith({
+ rowId: 'one',
+ columnId: 'name',
+ endRowId: 'one',
+ endColumnId: 'computed',
+ editing: false,
+ });
+ expect(cell('one', 2).contains(document.activeElement)).toBe(true);
+
+ press('ArrowDown', { shiftKey: true });
+ expect(selected()).toEqual(['one:1', 'one:2', 'two:1', 'two:2']);
+ expect(onCellFocus).toHaveBeenLastCalledWith({
+ rowId: 'one',
+ columnId: 'name',
+ endRowId: 'two',
+ endColumnId: 'computed',
+ editing: false,
+ });
+
+ press('ArrowLeft', { shiftKey: true });
+ expect(selected()).toEqual(['one:1', 'two:1']);
+
+ press('Delete');
+ await waitFor(() =>
+ expect(onClearCells).toHaveBeenCalledExactlyOnceWith(
+ ['one', 'two'],
+ ['name']
+ )
+ );
+ expect(onWrite).not.toHaveBeenCalled();
+ });
+
+ it('collapses to one cell on a plain arrow', () => {
+ const { onCellFocus } = setup();
+ cell('one', 1).focus();
+ press('ArrowDown', { shiftKey: true });
+ expect(selected()).toEqual(['one:1', 'two:1']);
+
+ press('ArrowRight');
+
+ expect(selected()).toEqual([]);
+ expect(onCellFocus).toHaveBeenLastCalledWith({
+ rowId: 'two',
+ columnId: 'computed',
+ editing: false,
+ });
+ });
+
+ it('jumps to the data edge with Shift+Cmd/Ctrl+Arrow and the row ends with Shift+Home/End, never into the blank new-record row', () => {
+ const { setRecords, setUnsavedRow } = setup();
+ setRecords([...rows, { rowId: 'draft', cells: {} }]);
+ setUnsavedRow('draft');
+ cell('one', 2).focus();
+
+ press('ArrowDown', { shiftKey: true, ctrlKey: true });
+ expect(selected()).toEqual(['one:2', 'two:2']);
+ press('ArrowDown', { shiftKey: true });
+ expect(selected()).toEqual(['one:2', 'two:2']);
+
+ press('End', { shiftKey: true });
+ expect(selected()).toEqual(['one:2', 'one:3', 'two:2', 'two:3']);
+ press('Home', { shiftKey: true });
+ expect(selected()).toEqual(['one:1', 'one:2', 'two:1', 'two:2']);
+ press('ArrowUp', { shiftKey: true, metaKey: true });
+ expect(selected()).toEqual(['one:1', 'one:2']);
+ });
+
+ it('selects every loaded cell with Cmd/Ctrl+A', () => {
+ const { onCellFocus } = setup();
+ cell('two', 2).focus();
+
+ press('a', { metaKey: true });
+
+ expect(selected()).toEqual([
+ 'one:1',
+ 'one:2',
+ 'one:3',
+ 'two:1',
+ 'two:2',
+ 'two:3',
+ ]);
+ expect(onCellFocus).toHaveBeenLastCalledWith({
+ rowId: 'one',
+ columnId: 'name',
+ endRowId: 'two',
+ endColumnId: 'notes',
+ editing: false,
+ });
+ });
+
+ it('leaves Shift+Arrow to an open cell editor', async () => {
+ setup();
+ fireEvent.click(
+ within(cell('one', 1)).getByRole('button', { name: /Name: First/ })
+ );
+ const editor = await screen.findByRole('textbox', { name: 'Edit Name' });
+
+ const handled = !fireEvent.keyDown(editor, {
+ key: 'ArrowRight',
+ shiftKey: true,
+ });
+
+ expect(handled).toBe(false);
+ expect(selected()).toEqual([]);
+ expect(document.activeElement).toBe(editor);
+ });
+});
diff --git a/apps/web/src/features/database/components/database-table.tsx b/apps/web/src/features/database/components/database-table.tsx
index c37eaf1ac0..0f6ae7d1e4 100644
--- a/apps/web/src/features/database/components/database-table.tsx
+++ b/apps/web/src/features/database/components/database-table.tsx
@@ -377,7 +377,18 @@ export function DatabaseTable(props: DatabaseTableProps) {
? { rowId: cell.rowId, columnId: cell.columnId }
: undefined;
},
+ canSelectRow: (rowId) => !props.isUnsavedRow?.(rowId),
focus: () => gridElement.focus({ preventScroll: true }),
+ // The corner may be in a row the virtualizer hasn't mounted yet.
+ focusCell: (cell) => {
+ pendingFocus = {
+ rowId: cell.rowId,
+ column: selection.columnIndex().get(cell.columnId)! + 1,
+ };
+ revealRow(cell.rowId);
+ focusRequestedCell();
+ queueMicrotask(focusRequestedCell);
+ },
onChange: (range) =>
announceCell(
range
diff --git a/apps/web/src/features/database/primitives/cell-selection.test.ts b/apps/web/src/features/database/primitives/cell-selection.test.ts
index 74415209d9..13a10cb188 100644
--- a/apps/web/src/features/database/primitives/cell-selection.test.ts
+++ b/apps/web/src/features/database/primitives/cell-selection.test.ts
@@ -1,6 +1,142 @@
import { createRoot, createSignal } from 'solid-js';
import { describe, expect, it } from 'vitest';
-import { createCellSelection } from './cell-selection';
+import { createCellSelection, extendCellRange } from './cell-selection';
+
+const rows = ['one', 'two', 'three', 'four'];
+const columns = ['name', 'status', 'notes'];
+
+describe('extending a cell range from the keyboard', () => {
+ it('moves the focus corner one cell and keeps the anchor', () => {
+ const range = {
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'two', columnId: 'status' },
+ };
+
+ expect(
+ extendCellRange(range, { key: 'ArrowDown', toEdge: false }, rows, columns)
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'three', columnId: 'status' },
+ });
+ expect(
+ extendCellRange(
+ range,
+ { key: 'ArrowRight', toEdge: false },
+ rows,
+ columns
+ )
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'two', columnId: 'notes' },
+ });
+ });
+
+ it('shrinks a range back toward its anchor and reverses past it', () => {
+ const range = {
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'three', columnId: 'status' },
+ };
+
+ const shrunk = extendCellRange(
+ range,
+ { key: 'ArrowUp', toEdge: false },
+ rows,
+ columns
+ );
+ const reversed = extendCellRange(
+ shrunk,
+ { key: 'ArrowUp', toEdge: false },
+ rows,
+ columns
+ );
+
+ expect(shrunk).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'two', columnId: 'status' },
+ });
+ expect(reversed).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'one', columnId: 'status' },
+ });
+ });
+
+ it('stops at the edges of the grid', () => {
+ const range = {
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'one', columnId: 'name' },
+ };
+
+ expect(
+ extendCellRange(range, { key: 'ArrowUp', toEdge: false }, rows, columns)
+ ).toEqual(range);
+ expect(
+ extendCellRange(range, { key: 'ArrowLeft', toEdge: false }, rows, columns)
+ ).toEqual(range);
+ expect(
+ extendCellRange(
+ {
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'four', columnId: 'notes' },
+ },
+ { key: 'ArrowDown', toEdge: false },
+ rows,
+ columns
+ )
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'four', columnId: 'notes' },
+ });
+ });
+
+ it('jumps to the edge of the data with Cmd/Ctrl and to the row ends with Home and End', () => {
+ const range = {
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'two', columnId: 'status' },
+ };
+
+ expect(
+ extendCellRange(range, { key: 'ArrowDown', toEdge: true }, rows, columns)
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'four', columnId: 'status' },
+ });
+ expect(
+ extendCellRange(range, { key: 'ArrowUp', toEdge: true }, rows, columns)
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'one', columnId: 'status' },
+ });
+ expect(
+ extendCellRange(range, { key: 'ArrowLeft', toEdge: true }, rows, columns)
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'two', columnId: 'name' },
+ });
+ expect(
+ extendCellRange(range, { key: 'Home', toEdge: false }, rows, columns)
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'two', columnId: 'name' },
+ });
+ expect(
+ extendCellRange(range, { key: 'End', toEdge: false }, rows, columns)
+ ).toEqual({
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'two', columnId: 'notes' },
+ });
+ });
+
+ it('leaves a range whose focus left the view unchanged', () => {
+ const range = {
+ anchor: { rowId: 'two', columnId: 'status' },
+ focus: { rowId: 'gone', columnId: 'status' },
+ };
+
+ expect(
+ extendCellRange(range, { key: 'ArrowDown', toEdge: false }, rows, columns)
+ ).toBe(range);
+ });
+});
describe('cell positions', () => {
it('keeps positions stable for value changes and updates them when rows or columns move', () => {
@@ -13,9 +149,11 @@ describe('cell positions', () => {
const selection = createCellSelection({
rows: () => rows().map((row) => row.id),
columns,
+ canSelectRow: () => true,
cellAt: () => undefined,
onChange: () => {},
focus: () => {},
+ focusCell: () => {},
});
const rowPositions = selection.rowIndex();
const columnPositions = selection.columnIndex();
diff --git a/apps/web/src/features/database/primitives/cell-selection.ts b/apps/web/src/features/database/primitives/cell-selection.ts
index 33602c777e..b9da026952 100644
--- a/apps/web/src/features/database/primitives/cell-selection.ts
+++ b/apps/web/src/features/database/primitives/cell-selection.ts
@@ -1,6 +1,7 @@
import { arrayEquals } from '@core/util/compareUtils';
import { fireAndForget } from '@core/util/fireAndForget';
import { createMemo, createSignal, onCleanup } from 'solid-js';
+import { match } from 'ts-pattern';
export type CellAddress = { rowId: string; columnId: string };
export type CellRange = { anchor: CellAddress; focus: CellAddress };
@@ -25,13 +26,69 @@ export function cellRangeBounds(
};
}
-/** Mouse ranges leave ordinary clicks and open cell editors to their existing controls. */
+export type CellRangeMove = {
+ key: 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End';
+ /** Cmd/Ctrl: run to the edge of the data. */
+ toEdge: boolean;
+};
+
+const RANGE_KEYS = new Set<string>([
+ 'ArrowUp',
+ 'ArrowDown',
+ 'ArrowLeft',
+ 'ArrowRight',
+ 'Home',
+ 'End',
+]);
+
+/** Move a range's focus corner like a spreadsheet's Shift+key, keeping its anchor and stopping at the grid's edges. */
+export function extendCellRange(
+ range: CellRange,
+ move: CellRangeMove,
+ rows: string[],
+ columns: string[]
+): CellRange {
+ const row = rows.indexOf(range.focus.rowId);
+ const column = columns.indexOf(range.focus.columnId);
+ if (row < 0 || column < 0) return range;
+ const lastRow = rows.length - 1;
+ const lastColumn = columns.length - 1;
+ const [nextRow, nextColumn] = match(move)
+ .with({ key: 'Home' }, () => [row, 0])
+ .with({ key: 'End' }, () => [row, lastColumn])
+ .with({ key: 'ArrowUp', toEdge: true }, () => [0, column])
+ .with({ key: 'ArrowUp' }, () => [Math.max(row - 1, 0), column])
+ .with({ key: 'ArrowDown', toEdge: true }, () => [lastRow, column])
+ .with({ key: 'ArrowDown' }, () => [Math.min(row + 1, lastRow), column])
+ .with({ key: 'ArrowLeft', toEdge: true }, () => [row, 0])
+ .with({ key: 'ArrowLeft' }, () => [row, Math.max(column - 1, 0)])
+ .with({ key: 'ArrowRight', toEdge: true }, () => [row, lastColumn])
+ .with({ key: 'ArrowRight' }, () => [row, Math.min(column + 1, lastColumn)])
+ .exhaustive();
+ return {
+ anchor: range.anchor,
+ focus: { rowId: rows[nextRow]!, columnId: columns[nextColumn]! },
+ };
+}
+
+const isPlainArrow = (event: KeyboardEvent) =>
+ event.key.startsWith('Arrow') &&
+ !event.shiftKey &&
+ !event.metaKey &&
+ !event.ctrlKey &&
+ !event.altKey;
+
+/** Mouse and keyboard ranges leave ordinary clicks and open cell editors to their existing controls. */
export function createCellSelection(options: {
rows: () => string[];
columns: () => string[];
+ /** Rows a range may take in, e.g. not the blank new-record row. */
+ canSelectRow: (rowId: string) => boolean;
cellAt: (target: EventTarget | null) => CellAddress | undefined;
onChange: (range: CellRange | undefined) => void;
focus: () => void;
+ /** Focus, and so scroll to, the corner a keyboard range moved to. */
+ focusCell: (cell: CellAddress) => void;
onClear?: (rows: string[], columns: string[]) => Promise<boolean>;
}) {
const [range, setRange] = createSignal<CellRange>();
@@ -43,6 +100,9 @@ export function createCellSelection(options: {
const columnIndex = createMemo(
() => new Map(columnIds().map((id, index) => [id, index]))
);
+ const selectableRows = createMemo(() =>
+ options.rows().filter(options.canSelectRow)
+ );
const bounds = createMemo(() => {
const selected = range();
return selected && cellRangeBounds(selected, rowIndex(), columnIndex());
@@ -62,6 +122,51 @@ export function createCellSelection(options: {
!!target.closest(
'input:not([type="checkbox"]), textarea, [contenteditable="true"], [role="menu"], [role="dialog"]'
);
+ /** Cmd/Ctrl+A on a cell takes in every loaded, selectable cell. */
+ const selectAll = (event: KeyboardEvent) => {
+ if (
+ !(event.metaKey || event.ctrlKey) ||
+ event.shiftKey ||
+ event.altKey ||
+ event.key.toLowerCase() !== 'a' ||
+ !options.cellAt(event.target)
+ )
+ return false;
+ const rows = selectableRows();
+ const columns = options.columns();
+ if (!rows.length || !columns.length) return false;
+ anchor = { rowId: rows[0]!, columnId: columns[0]! };
+ select({
+ anchor,
+ focus: { rowId: rows.at(-1)!, columnId: columns.at(-1)! },
+ });
+ return true;
+ };
+ /** Shift+Arrow/Home/End move the focus corner, starting from the focused cell. */
+ const extend = (event: KeyboardEvent) => {
+ if (!event.shiftKey || event.altKey || !RANGE_KEYS.has(event.key))
+ return false;
+ const cell = options.cellAt(event.target);
+ const current = range() ?? (cell && { anchor: cell, focus: cell });
+ if (!current) return false;
+ const next = extendCellRange(
+ current,
+ {
+ key: event.key as CellRangeMove['key'],
+ toEdge: event.metaKey || event.ctrlKey,
+ },
+ selectableRows(),
+ options.columns()
+ );
+ const moved =
+ next.focus.rowId !== current.focus.rowId ||
+ next.focus.columnId !== current.focus.columnId;
+ if (!range() && !moved) return true;
+ anchor = next.anchor;
+ select(next);
+ options.focusCell(next.focus);
+ return true;
+ };
const pointerDown = (event: PointerEvent) => {
if (
event.button !== 0 ||
@@ -147,6 +252,16 @@ export function createCellSelection(options: {
},
keyDown: (event: KeyboardEvent) => {
if (event.isComposing || isEditor(event.target)) return;
+ if (selectAll(event) || extend(event)) {
+ event.preventDefault();
+ event.stopPropagation();
+ return;
+ }
+ // A plain arrow collapses the range; the grid then moves focus as usual.
+ if (isPlainArrow(event) && range()) {
+ select(undefined);
+ return;
+ }
if (event.key === 'Escape' && range()) {
event.preventDefault();
event.stopPropagation();
diff --git a/apps/web/src/features/database/views/database-records-view.test.tsx b/apps/web/src/features/database/views/database-records-view.test.tsx
index 7602f48b58..752c54daca 100644
--- a/apps/web/src/features/database/views/database-records-view.test.tsx
+++ b/apps/web/src/features/database/views/database-records-view.test.tsx
@@ -955,6 +955,60 @@ describe('database table view', () => {
}
);
+ it('clears a Shift+Arrow range in one write, so one undo restores it', async () => {
+ const fixture = createFakeRowsSource({
+ columns,
+ table: {
+ version: 1,
+ rows: [
+ { rowId: 'plan', cells: { title: 'Plan launch', status: 'todo' } },
+ { rowId: 'ship', cells: { title: 'Ship it', status: 'done' } },
+ ],
+ },
+ view: allRecords,
+ });
+ fixture.persistWrites();
+ render(() => (
+ <DatabaseRecordsView
+ name="Projects"
+ source={fixture.source}
+ canEdit
+ view={allRecords}
+ stored={false}
+ addColumn={() => null}
+ boardPositions={unplacedCards}
+ />
+ ));
+ await screen.findByRole('button', { name: 'Open Ship it' });
+ document
+ .querySelector<HTMLElement>(
+ '[data-grid-row-id="plan"] [data-grid-column="1"]'
+ )!
+ .focus();
+
+ fireEvent.keyDown(document.activeElement!, {
+ key: 'ArrowRight',
+ shiftKey: true,
+ });
+ fireEvent.keyDown(document.activeElement!, {
+ key: 'ArrowDown',
+ shiftKey: true,
+ });
+ fireEvent.keyDown(document.activeElement!, { key: 'Delete' });
+
+ await waitFor(() =>
+ expect(fixture.source.write).toHaveBeenCalledExactlyOnceWith(
+ {
+ kind: 'clear',
+ rowIds: ['plan', 'ship'],
+ columnIds: ['title', 'status'],
+ },
+ 1,
+ false
+ )
+ );
+ });
+
it('focuses a new column header and edits its cells in a row created from the blank draft', async () => {
const fixture = createFakeRowsSource({
columns,
diff --git a/docs/agent-guide/databases.md b/docs/agent-guide/databases.md
index 064aeddc07..254ef19b92 100644
--- a/docs/agent-guide/databases.md
+++ b/docs/agent-guide/databases.md
@@ -331,7 +331,11 @@ after, so a 1 PM to 5 PM range contains its day. Properties of type **Time range
edit with the same fields.
Invalid numbers remain in the editor for correction.
Drag across table cells to select a rectangle, or Shift-click another cell to
-extend from the first cell. Delete or Backspace clears editable cells in that
+extend from the first cell. From the keyboard, Shift+Arrow grows or shrinks the
+rectangle from the focused cell, Shift+Cmd/Ctrl+Arrow runs to the edge of the
+data, Shift+Home/End to the ends of the row, and Cmd/Ctrl+A selects every loaded
+cell; a plain arrow collapses it. Inside an open cell editor Shift+Arrow selects
+text as usual. Delete or Backspace clears editable cells in that
rectangle as one undoable change; read-only cells are skipped. Newly saved rows
can be included immediately; unsaved insertion rows are excluded. Escape clears
the selection. Other participants see the selected range with a colored outline and