Skip to content

Add zoom controls to View menu with custom role menu item#48

Merged
fgilio merged 2 commits intomainfrom
claude/fix-rfa-zoom-shortcuts-Hux5a
Apr 24, 2026
Merged

Add zoom controls to View menu with custom role menu item#48
fgilio merged 2 commits intomainfrom
claude/fix-rfa-zoom-shortcuts-Hux5a

Conversation

@fgilio
Copy link
Copy Markdown
Owner

@fgilio fgilio commented Apr 24, 2026

Summary

This PR adds zoom in, zoom out, and reset zoom controls to the application's View menu. Since NativePHP's RolesEnum doesn't expose Electron's zoom roles, a new ZoomRoleMenuItem class was created to support these role-type menu items directly.

Key Changes

  • New ZoomRoleMenuItem class: A custom menu item that extends NativePHP's MenuItem to support Electron's zoom roles (zoomIn, zoomOut, resetZoom) with proper serialization
  • Updated View menu: Added three zoom control menu items ("Actual Size", "Zoom In", "Zoom Out") with their standard keyboard accelerators (⌘0, ⌘+, ⌘-)
  • Menu reorganization: Restructured the View menu to include zoom controls while maintaining the existing dev tools and fullscreen options
  • Comprehensive tests: Added unit tests verifying the ZoomRoleMenuItem correctly serializes with and without labels

Implementation Details

The ZoomRoleMenuItem class bypasses NativePHP's limitations by directly setting the type to 'role' and including the role string in the serialized output. This allows Electron to bind the standard zoom accelerators automatically. The zoom items are positioned at the top of the View menu for better UX, with separators organizing the menu logically.

https://claude.ai/code/session_01XDyuWuYkRBcRS8MtLv7oQM

Summary by CodeRabbit

  • New Features
    • Added zoom controls (Zoom In, Zoom Out, Actual Size) to the View menu in the desktop application interface.

Releasing ⌘R (#44) replaced Menu::view() with a custom submenu that
only kept devTools and fullscreen. That also dropped the viewMenu
role's built-in zoom items, so ⌘+, ⌘-, and ⌘0 no longer did anything.

NativePHP's RolesEnum doesn't expose zoomIn/zoomOut/resetZoom, but
Electron accepts the role strings directly with their default
accelerators attached. ZoomRoleMenuItem emits the raw role so we can
reattach them to the custom View menu.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

Warning

Rate limit exceeded

@fgilio has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 30 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 55 minutes and 30 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 418e5670-3a03-4eca-8885-4d6672fd9403

📥 Commits

Reviewing files that changed from the base of the PR and between 28249cc and 19c2f2f.

📒 Files selected for processing (1)
  • tests/Unit/Support/ZoomRoleMenuItemTest.php
📝 Walkthrough

Walkthrough

The changes introduce zoom role menu items (resetZoom, zoomIn, zoomOut) to the View submenu in the native app service provider, create a new ZoomRoleMenuItem class to handle Electron role-based menu items, and add comprehensive unit tests for the new class.

Changes

Cohort / File(s) Summary
Native App Menu Configuration
app/Providers/NativeAppServiceProvider.php
Added explicit zoom role menu items to the View submenu. Repositioned separators and Menu::devTools() call. Extended comment clarifying that zoom bindings are not exposed via NativePHP's RolesEnum.
Zoom Menu Item Class
app/Support/ZoomRoleMenuItem.php
New final class implementing a menu item type with forced 'role' type. Accepts role string (e.g., zoomIn, zoomOut, resetZoom) and optional label, overriding toArray() to include the role field.
Unit Tests
tests/Unit/Support/ZoomRoleMenuItemTest.php
Test suite for ZoomRoleMenuItem verifying serialization behavior with and without labels. Asserts correct type, role, and optional label fields in array output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Zoom in, zoom out, let's see it all,
The rabbit's View menu answers the call,
With roles so clear in Electron's domain,
We hop through the pixels, again and again!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the primary change: adding zoom controls to the View menu using a custom role menu item class.
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
  • Commit unit tests in branch claude/fix-rfa-zoom-shortcuts-Hux5a

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
tests/Unit/Support/ZoomRoleMenuItemTest.php (2)

10-14: Consider tightening the positive assertion.

toMatchArray only checks the subset — extra/unexpected keys (e.g., a stale role inherited from the parent, or unintended fields) would pass silently. If you want to lock the full payload down, switch to toEqual with the exact shape, or add a key-count assertion. Not a blocker for this PR.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/Support/ZoomRoleMenuItemTest.php` around lines 10 - 14, The test
currently uses toMatchArray on $array which only checks a subset and can miss
extra/unexpected keys; update the assertion in ZoomRoleMenuItemTest (the
expectation against $array) to assert the exact shape — either replace
toMatchArray with toEqual using the full expected array
('type'=>'role','role'=>'zoomIn','label'=>'Zoom In') or add an explicit
key-count/assertCount check to ensure no extra keys are present so the payload
is fully locked down.

17-23: Optional: chain expectations on the same subject for readability.

Per project guidelines, chain multiple expectations on the same subject when readable.

♻️ Suggested chain
 test('omits label when none is provided', function () {
     $array = (new ZoomRoleMenuItem('resetZoom'))->toArray();

-    expect($array['type'])->toBe('role');
-    expect($array['role'])->toBe('resetZoom');
-    expect($array)->not->toHaveKey('label');
+    expect($array)
+        ->type->toBe('role')
+        ->role->toBe('resetZoom')
+        ->not->toHaveKey('label');
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/Support/ZoomRoleMenuItemTest.php` around lines 17 - 23, The test
uses three separate expect(...) calls on the same $array subject; replace them
with a chained assertion for readability — e.g. call
expect($array)->toMatchArray(['type' => 'role', 'role' =>
'resetZoom'])->not->toHaveKey('label') in the "omits label when none is
provided" test that constructs the ZoomRoleMenuItem, so all checks target the
same subject in one fluent chain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/Unit/Support/ZoomRoleMenuItemTest.php`:
- Around line 10-14: The test currently uses toMatchArray on $array which only
checks a subset and can miss extra/unexpected keys; update the assertion in
ZoomRoleMenuItemTest (the expectation against $array) to assert the exact shape
— either replace toMatchArray with toEqual using the full expected array
('type'=>'role','role'=>'zoomIn','label'=>'Zoom In') or add an explicit
key-count/assertCount check to ensure no extra keys are present so the payload
is fully locked down.
- Around line 17-23: The test uses three separate expect(...) calls on the same
$array subject; replace them with a chained assertion for readability — e.g.
call expect($array)->toMatchArray(['type' => 'role', 'role' =>
'resetZoom'])->not->toHaveKey('label') in the "omits label when none is
provided" test that constructs the ZoomRoleMenuItem, so all checks target the
same subject in one fluent chain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9cd81700-831c-4538-ab76-6dd55799193d

📥 Commits

Reviewing files that changed from the base of the PR and between 7622d08 and 28249cc.

📒 Files selected for processing (3)
  • app/Providers/NativeAppServiceProvider.php
  • app/Support/ZoomRoleMenuItem.php
  • tests/Unit/Support/ZoomRoleMenuItemTest.php

@fgilio fgilio merged commit c5b49e6 into main Apr 24, 2026
15 of 17 checks passed
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.

2 participants