Skip to content

special first click handling for macos. cancel the click but set block/waveai focus#3098

Merged
sawka merged 1 commit intomainfrom
sawka/macos-first-click
Mar 21, 2026
Merged

special first click handling for macos. cancel the click but set block/waveai focus#3098
sawka merged 1 commit intomainfrom
sawka/macos-first-click

Conversation

@sawka
Copy link
Member

@sawka sawka commented Mar 20, 2026

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

Walkthrough

This pull request introduces macOS first-click handling infrastructure by adding a new event handler component that listens to focus and mouse events, implementing logic to prevent and cancel the first click after a window focus event when occurring within a 50ms window. The changes include configuration updates for Electron on macOS, DOM attribute additions for component identification, a new MacOSFirstClickHandler React component with event listener registration and conditional focus management, and import/export reorganization across the store modules. Copyright years are updated to 2026, and a debug console.log statement is removed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess relevance to the changeset. Add a pull request description explaining the purpose, implementation details, and testing approach for the macOS first-click handling feature.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding special first click handling for macOS that cancels the initial click while setting block/AI panel focus.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sawka/macos-first-click

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.

@sawka
Copy link
Member Author

sawka commented Mar 20, 2026

fix for #2982

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 20, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (5 files)
  • emain/emain-window.ts - Adds macOS-specific acceptFirstMouse option
  • frontend/app/aipanel/aipanel.tsx - Adds data-aipanel attribute for click detection
  • frontend/app/app.tsx - Implements MacOSFirstClickHandler component
  • frontend/app/store/focusManager.ts - Copyright year update
  • frontend/app/store/global.ts - Reorders exports, removes debug log

Implementation Notes

The PR correctly implements special first-click handling for macOS:

  1. Electron config (emain-window.ts:170): Sets acceptFirstMouse = true on macOS to enable the first-click activation behavior
  2. Click detection (app.tsx:238-261): Uses a 50ms threshold after window focus to detect "first clicks"
  3. Focus management: Properly cancels the initial click event while scheduling focus to either the clicked block or AI panel
  4. Cleanup: Correctly removes event listeners on component unmount

The code follows existing patterns in the codebase and properly uses the existing refocusNode and FocusManager utilities.


Reviewed by minimax-m2.5-20260211 · 439,700 tokens

Copy link
Contributor

@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 (1)
frontend/app/app.tsx (1)

207-282: Consider removing debug console.log statements before merge.

The MacOSFirstClickHandler implementation is correct for intercepting the macOS first-click behavior. A few observations:

  1. Lines 248, 253, 257, 270: Multiple console.log statements appear to be debug artifacts. Consider removing or converting to the existing focusLog debug logger for consistency with the rest of the file.

  2. The 50ms timing window (line 240) and 10ms setTimeout delays (lines 247, 252) are reasonable for ensuring the focus event has fully propagated before applying custom focus logic.

  3. The capture phase listeners (lines 273-274) correctly ensure this handler runs before other event handlers.

🧹 Suggested cleanup for console.log statements
 const handleMouseDown = (e: MouseEvent) => {
     const timeDiff = Date.now() - windowFocusTime;
     if (windowFocusTime != null && timeDiff < 50) {
         e.preventDefault();
         e.stopPropagation();
         e.stopImmediatePropagation();
         cancelNextClick = true;
         const blockId = getBlockIdFromTarget(e.target);
         if (blockId != null) {
             setTimeout(() => {
-                console.log("macos first-click, focusing block", blockId);
+                focusLog("macos first-click, focusing block", blockId);
                 refocusNode(blockId);
             }, 10);
         } else if (isAIPanelTarget(e.target)) {
             setTimeout(() => {
-                console.log("macos first-click, focusing AI panel");
+                focusLog("macos first-click, focusing AI panel");
                 FocusManager.getInstance().setWaveAIFocused(true);
             }, 10);
         }
-        console.log("macos first-click detected, canceled", timeDiff + "ms");
+        focusLog("macos first-click detected, canceled", timeDiff + "ms");
         return;
     }
     cancelNextClick = false;
 };
 const handleClick = (e: MouseEvent) => {
     if (!cancelNextClick) {
         return;
     }
     cancelNextClick = false;
     e.preventDefault();
     e.stopPropagation();
     e.stopImmediatePropagation();
-    console.log("macos first-click (click event) canceled");
+    focusLog("macos first-click (click event) canceled");
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/app/app.tsx` around lines 207 - 282, Remove the debug console.log
calls in MacOSFirstClickHandler: replace the console.log in the setTimeout
inside handleMouseDown that logs "macos first-click, focusing block", the one
that logs "macos first-click, focusing AI panel", the "macos first-click
detected, canceled" in handleMouseDown, and the "macos first-click (click event)
canceled" in handleClick with the project's debug logger (e.g., focusLog.debug
or similar) or delete them if no logging is desired; update references in the
setTimeout callbacks and both handlers (handleMouseDown, handleClick) so no
console.log calls remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@frontend/app/app.tsx`:
- Around line 207-282: Remove the debug console.log calls in
MacOSFirstClickHandler: replace the console.log in the setTimeout inside
handleMouseDown that logs "macos first-click, focusing block", the one that logs
"macos first-click, focusing AI panel", the "macos first-click detected,
canceled" in handleMouseDown, and the "macos first-click (click event) canceled"
in handleClick with the project's debug logger (e.g., focusLog.debug or similar)
or delete them if no logging is desired; update references in the setTimeout
callbacks and both handlers (handleMouseDown, handleClick) so no console.log
calls remain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5c938874-a2a3-4d67-a1d8-6c2f09d9288b

📥 Commits

Reviewing files that changed from the base of the PR and between 884884f and 46e9a4f.

📒 Files selected for processing (5)
  • emain/emain-window.ts
  • frontend/app/aipanel/aipanel.tsx
  • frontend/app/app.tsx
  • frontend/app/store/focusManager.ts
  • frontend/app/store/global.ts

@sawka sawka merged commit 8fc4dc3 into main Mar 21, 2026
8 checks passed
@sawka sawka deleted the sawka/macos-first-click branch March 21, 2026 00:49
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