✨(frontend) add keyboard shortcut to toggle presenter mode#2426
✨(frontend) add keyboard shortcut to toggle presenter mode#2426maboukerfa wants to merge 1 commit into
Conversation
Mod+Alt+P (Ctrl+Alt+P / Cmd+Option+P) now opens and closes the presenter from the document page. Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
WalkthroughThis PR adds keyboard shortcut support for toggling the presenter view in the document editor. A new Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/frontend/apps/impress/src/features/docs/doc-presenter/__tests__/usePresenterToggleShortcut.spec.ts`:
- Around line 18-52: Add a regression test that ensures AltGraph doesn't trigger
the presenter toggle: in the existing usePresenterToggleShortcut tests
(referencing renderShortcut and the press helper), add a new test that calls
renderShortcut(), then calls press({ code: 'KeyP', ctrlKey: true, altKey: true,
altGraph: true }) and asserts the onToggle mock was not called; keep the test
name descriptive (e.g., 'AltGraph does not trigger presenter toggle') and mirror
the pattern of the other tests.
In
`@src/frontend/apps/impress/src/features/docs/doc-presenter/hooks/usePresenterToggleShortcut.ts`:
- Around line 19-24: The shortcut predicate in usePresenterToggleShortcut's
keydown handler currently treats simultaneous ctrlKey+altKey as Mod+Alt and can
be triggered by AltGraph on international keyboards; update the predicate to
explicitly exclude AltGraph by checking event.getModifierState('AltGraph')
(i.e., require !event.getModifierState('AltGraph')) alongside the existing
checks for event.ctrlKey/event.metaKey and event.altKey so AltGr won't produce a
false positive when pressing Mod+Alt+P.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: f874993f-b79f-4d3e-bac9-e3c53b7d302e
📒 Files selected for processing (3)
src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsxsrc/frontend/apps/impress/src/features/docs/doc-presenter/__tests__/usePresenterToggleShortcut.spec.tssrc/frontend/apps/impress/src/features/docs/doc-presenter/hooks/usePresenterToggleShortcut.ts
| describe('usePresenterToggleShortcut', () => { | ||
| test('Ctrl+Alt+P and Meta+Alt+P call onToggle', () => { | ||
| const onToggle = renderShortcut(); | ||
| press({ code: 'KeyP', ctrlKey: true, altKey: true }); | ||
| press({ code: 'KeyP', metaKey: true, altKey: true }); | ||
| expect(onToggle).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| test('Mod+Alt+P prevents default', () => { | ||
| renderShortcut(); | ||
| const event = press({ code: 'KeyP', ctrlKey: true, altKey: true }); | ||
| expect(event.defaultPrevented).toBe(true); | ||
| }); | ||
|
|
||
| test('KeyP without the full modifier combination is ignored', () => { | ||
| const onToggle = renderShortcut(); | ||
| press({ code: 'KeyP' }); | ||
| press({ code: 'KeyP', ctrlKey: true }); | ||
| press({ code: 'KeyP', altKey: true }); | ||
| press({ code: 'KeyP', ctrlKey: true, altKey: true, shiftKey: true }); | ||
| expect(onToggle).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('repeat events are ignored', () => { | ||
| const onToggle = renderShortcut(); | ||
| press({ code: 'KeyP', ctrlKey: true, altKey: true, repeat: true }); | ||
| expect(onToggle).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('does nothing when disabled', () => { | ||
| const onToggle = renderShortcut(false); | ||
| press({ code: 'KeyP', ctrlKey: true, altKey: true }); | ||
| expect(onToggle).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Add a regression test to ensure AltGraph does not trigger presenter toggle.
Please add a non-trigger case so keyboard-layout regressions are caught when ctrlKey + altKey comes from AltGraph.
Suggested test addition
test('does nothing when disabled', () => {
const onToggle = renderShortcut(false);
press({ code: 'KeyP', ctrlKey: true, altKey: true });
expect(onToggle).not.toHaveBeenCalled();
});
+
+ test('AltGraph+P is ignored', () => {
+ const onToggle = renderShortcut();
+ const event = press({ code: 'KeyP', ctrlKey: true, altKey: true });
+ Object.defineProperty(event, 'getModifierState', {
+ value: (key: string) => key === 'AltGraph',
+ });
+ window.dispatchEvent(event);
+ expect(onToggle).not.toHaveBeenCalled();
+ });
});🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/frontend/apps/impress/src/features/docs/doc-presenter/__tests__/usePresenterToggleShortcut.spec.ts`
around lines 18 - 52, Add a regression test that ensures AltGraph doesn't
trigger the presenter toggle: in the existing usePresenterToggleShortcut tests
(referencing renderShortcut and the press helper), add a new test that calls
renderShortcut(), then calls press({ code: 'KeyP', ctrlKey: true, altKey: true,
altGraph: true }) and asserts the onToggle mock was not called; keep the test
name descriptive (e.g., 'AltGraph does not trigger presenter toggle') and mirror
the pattern of the other tests.
| if ( | ||
| event.code === 'KeyP' && | ||
| (event.ctrlKey || event.metaKey) && | ||
| event.altKey && | ||
| !event.shiftKey && | ||
| !event.repeat |
There was a problem hiding this comment.
Guard against AltGraph false positives in the shortcut predicate.
On international layouts, AltGr commonly sets both ctrlKey and altKey; at Line 21–22 this can unintentionally satisfy Mod+Alt+P and toggle presenter while typing. Exclude AltGraph explicitly.
Suggested patch
if (
event.code === 'KeyP' &&
(event.ctrlKey || event.metaKey) &&
event.altKey &&
+ !event.getModifierState('AltGraph') &&
!event.shiftKey &&
!event.repeat
) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if ( | |
| event.code === 'KeyP' && | |
| (event.ctrlKey || event.metaKey) && | |
| event.altKey && | |
| !event.shiftKey && | |
| !event.repeat | |
| if ( | |
| event.code === 'KeyP' && | |
| (event.ctrlKey || event.metaKey) && | |
| event.altKey && | |
| !event.getModifierState('AltGraph') && | |
| !event.shiftKey && | |
| !event.repeat | |
| ) { |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/frontend/apps/impress/src/features/docs/doc-presenter/hooks/usePresenterToggleShortcut.ts`
around lines 19 - 24, The shortcut predicate in usePresenterToggleShortcut's
keydown handler currently treats simultaneous ctrlKey+altKey as Mod+Alt and can
be triggered by AltGraph on international keyboards; update the predicate to
explicitly exclude AltGraph by checking event.getModifierState('AltGraph')
(i.e., require !event.getModifierState('AltGraph')) alongside the existing
checks for event.ctrlKey/event.metaKey and event.altKey so AltGr won't produce a
false positive when pressing Mod+Alt+P.
Purpose
Add a keyboard shortcut (
Mod+Alt+P(Ctrl+Alt+Pon Windows/Linux,⌘⌥Pon macOS) to toggle presenter mode from the document page, so users can start and stop presenting without reaching for the toolbox menu.Screen.Recording.2026-06-13.at.16.55.23.mov