Skip to content

✨(frontend) add keyboard shortcut to toggle presenter mode#2426

Open
maboukerfa wants to merge 1 commit into
suitenumerique:mainfrom
maboukerfa:feature/presenter-toggle-shortcut
Open

✨(frontend) add keyboard shortcut to toggle presenter mode#2426
maboukerfa wants to merge 1 commit into
suitenumerique:mainfrom
maboukerfa:feature/presenter-toggle-shortcut

Conversation

@maboukerfa

@maboukerfa maboukerfa commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Purpose

Add a keyboard shortcut (Mod+Alt+P (Ctrl+Alt+P on Windows/Linux, ⌘⌥P on 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

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>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds keyboard shortcut support for toggling the presenter view in the document editor. A new usePresenterToggleShortcut hook detects when the user presses Mod+Alt+P, calls a provided callback, and prevents the default browser action. The hook includes an enabled flag to conditionally activate the shortcut. The hook is integrated into DocToolBox, wiring it to toggle the presenter state when the document is not deleted and the user is not on mobile. Full test coverage validates the shortcut behavior across modifier combinations, repeat events, and disabled states.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • AntoLC
  • Ovgodd
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a keyboard shortcut to toggle presenter mode, which aligns with all modified files.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of the keyboard shortcut feature and its use case.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f984d6 and 841f4dd.

📒 Files selected for processing (3)
  • src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx
  • src/frontend/apps/impress/src/features/docs/doc-presenter/__tests__/usePresenterToggleShortcut.spec.ts
  • src/frontend/apps/impress/src/features/docs/doc-presenter/hooks/usePresenterToggleShortcut.ts

Comment on lines +18 to +52
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();
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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.

Comment on lines +19 to +24
if (
event.code === 'KeyP' &&
(event.ctrlKey || event.metaKey) &&
event.altKey &&
!event.shiftKey &&
!event.repeat

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant