Skip to content

Commit d3a3e30

Browse files
SamTV12345claude
andauthored
fix(sheet): Delete clears a single selected cell (#364)
Delete/Backspace only cleared multi-cell ranges; a single selected cell was left to native contenteditable, unlike Excel. Replace the single-cell exclusion with a grid-focus guard: Delete now clears one cell too, while Backspace still edits the formula bar (and any input outside the grid). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a2d914a commit d3a3e30

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

playwright/specs/sheet_selection.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,26 @@ test.describe('Sheet selection, fill, and clipboard', () => {
135135
await expect(cell(page, 2, 1)).toHaveText('bar', { timeout: 10000 });
136136
});
137137
});
138+
139+
test('Delete clears a single selected cell', async ({ page }) => {
140+
const padId = `sheet-del1-${Date.now()}`;
141+
await openSheet(page, padId);
142+
await commitCell(page, 0, 0, 'hallo'); // A1
143+
await cell(page, 0, 0).click();
144+
await page.keyboard.press('Delete');
145+
await expect(cell(page, 0, 0)).toHaveText('');
146+
});
147+
148+
test('Backspace in the formula bar edits the formula, not clears the cell', async ({ page }) => {
149+
const padId = `sheet-fxbksp-${Date.now()}`;
150+
await openSheet(page, padId);
151+
await commitCell(page, 0, 0, 'abc'); // A1
152+
await cell(page, 0, 0).click();
153+
const fx = page.locator('.sheet-fx-input');
154+
await fx.click();
155+
await page.keyboard.press('Backspace'); // must act on fx text, not wipe A1
156+
await page.keyboard.press('Escape'); // cancel the edit
157+
// If the document Delete handler had fired, A1 would be empty regardless.
158+
await expect(cell(page, 0, 0)).toHaveText('abc');
159+
});
138160
});

ui/src/js/sheet/sheetEditor.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,15 @@ export function startSheetEditor(root: HTMLElement): void {
573573
doPaste();
574574
return;
575575
}
576-
if ((e.key === 'Delete' || e.key === 'Backspace') && !editingNow() && !readOnly && !selIsSingle(selection)) {
576+
// Clear the selection (single cell or range), like Excel. The grid-focus
577+
// guard replaces the old single-cell exclusion: it lets Delete clear one
578+
// cell while still keeping Backspace working in the formula bar and any
579+
// other input outside the grid (selection is single there too).
580+
if (
581+
(e.key === 'Delete' || e.key === 'Backspace') &&
582+
!editingNow() && !readOnly &&
583+
(e.target as HTMLElement | null)?.closest?.('.sheet-grid')
584+
) {
577585
e.preventDefault();
578586
blurActiveCell();
579587
const { r0, c0, r1, c1 } = normalize(selection);

0 commit comments

Comments
 (0)