feat(sheet): Ctrl+B/I/U toggle bold, italic, underline - #365
Conversation
Keyboard shortcuts for the ribbon's style toggles, applied to the current selection. Skips real form fields so the formula bar keeps these keys, and does NOT require grid focus (applying a style blurs the cell, so requiring focus would break chaining B then I). preventDefault stops the browser's contenteditable rich-text default. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
PR Summary by QodoSheet: Add Ctrl/Cmd B/I/U formatting shortcuts
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Repeat toggles style twice
|
| if (mod && !editingNow() && !readOnly && !inField) { | ||
| const k = e.key.toLowerCase(); | ||
| const styleKey = k === 'b' ? 'bold' : k === 'i' ? 'italic' : k === 'u' ? 'underline' : null; | ||
| if (styleKey) { | ||
| e.preventDefault(); | ||
| const on = propsOf(selection.focus.row, selection.focus.col)[styleKey] === '1'; | ||
| applyStyleToSelection({ [styleKey]: on ? '' : '1' }); | ||
| return; |
There was a problem hiding this comment.
1. Repeat toggles style twice 🐞 Bug ≡ Correctness
The Ctrl/Cmd+B/I/U handler runs on every keydown event without checking KeyboardEvent.repeat, so holding the shortcut can flip the style multiple times and leave the selection in the wrong final state.
Agent Prompt
### Issue description
The Ctrl/Cmd+B/I/U shortcut toggles style on *every* `keydown`, including auto-repeat events when the key is held. This can cause multiple toggles and an unintended final style state.
### Issue Context
The handler is attached at the document level and calls `applyStyleToSelection()` immediately when it detects Ctrl/Cmd + (b/i/u).
### Fix Focus Areas
- Add an `e.repeat` guard so toggles only apply once per physical key press.
- ui/src/js/sheet/sheetEditor.ts[558-593]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| await page.keyboard.press('Control+b'); | ||
| await expect(cell(page, 0, 0)).toHaveCSS('font-weight', /700|bold/); | ||
| await page.keyboard.press('Control+i'); | ||
| await expect(cell(page, 0, 0)).toHaveCSS('font-style', 'italic'); | ||
| await page.keyboard.press('Control+u'); | ||
| await expect(cell(page, 0, 0)).toHaveCSS('text-decoration', /underline/); | ||
|
|
||
| // Ctrl+B again toggles bold back off. | ||
| await page.keyboard.press('Control+b'); | ||
| await expect(cell(page, 0, 0)).toHaveCSS('font-weight', /400|normal/); |
There was a problem hiding this comment.
2. Cmd path untested 🐞 Bug ☼ Reliability
The implementation supports Cmd shortcuts via e.metaKey, but the new Playwright test only presses Control+b/i/u, so it will not catch regressions specific to the metaKey path.
Agent Prompt
### Issue description
The shortcut handler treats Ctrl and Cmd equivalently (`e.ctrlKey || e.metaKey`), but the added e2e test only exercises the Ctrl path.
### Issue Context
This is a coverage gap: it doesn't prove Cmd is broken, but it reduces confidence for macOS users.
### Fix Focus Areas
- Add a variant that presses `Meta+b/i/u` (or parameterize by modifier), ideally in a way that won't be flaky on non-mac runners.
- playwright/specs/sheet_excel_chrome.spec.ts[54-70]
- ui/src/js/sheet/sheetEditor.ts[558-593]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
What
Keyboard shortcuts Ctrl/Cmd+B / +I / +U to toggle bold, italic, underline on the current selection — mirroring the ribbon's existing toggle buttons.
How
Added to the document keydown handler. Two deliberate guard choices:
INPUT/TEXTAREA/SELECT) so the formula bar keeps these keys — but do not require grid focus, because applying a style blurs the active cell; requiring focus would break chaining (press B, then I).preventDefaultstops the browser's nativecontenteditablerich-text formatting on the focused cell.Toggle reads the focus cell's prop (
bold/italic/underline='1') and flips it via the sameapplyStyleToSelectionthe buttons use.Tests
sheet_excel_chrome.spec.tstest: B→bold, I→italic, U→underline, then B again → back to normal.sheet_excel_chrome+sheet_selectionspecs locally (15 tests) — all pass, incl. the existing Delete/formula-bar tests (shared keydown handler, no regression).🤖 Generated with Claude Code