Skip to content

🐛 Fixed search navigating away during CJK IME composition#26878

Open
sailor95 wants to merge 1 commit intoTryGhost:mainfrom
sailor95:fix/sodo-search-ime-composition-enter
Open

🐛 Fixed search navigating away during CJK IME composition#26878
sailor95 wants to merge 1 commit intoTryGhost:mainfrom
sailor95:fix/sodo-search-ime-composition-enter

Conversation

@sailor95
Copy link

@sailor95 sailor95 commented Mar 18, 2026

When using CJK input methods (Chinese, Japanese, Korean) in the sodo-search modal (Cmd+K), pressing Enter to confirm a character during IME composition incorrectly triggers navigation to the first search result. This makes search unusable for CJK users.

The keyboard handler in the Results component used keyup, but compositionend fires before keyup, so event.isComposing is already false by then. Switched to keydown where isComposing reliably reflects the composition state.

Demo

Before (main branch)

pr-26878.mp4
  • Type "測試" using zh-Hant IME while characters are still being composed
  • Press Enter to confirm composition
  • The search immediately redirects to the 1st result instead of finalizing the composed text and letting the user select their intented result

After (PR branch)

pr-26878-after.mov
  • Type "測試" using zh-Hant IME while characters are still being composed
  • Press Enter to confirm composition
  • Search results remain, letting user manually pick search item

Note

Low Risk
Low risk: small change to keyboard event handling in the search results list; main risk is unintended key handling differences between keyup and keydown for navigation/Enter behavior.

Overview
Fixes Cmd+K search result navigation for CJK IME users by moving the results keyboard listener from keyup to keydown and ignoring events during composition (event.isComposing / legacy keyCode === 229).

This prevents Enter presses used to confirm IME text from triggering immediate navigation to the currently selected search result.

Written by Cursor Bugbot for commit 866ecec. This will update automatically on new commits. Configure here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ee46ddfb-6beb-4b57-a532-de8fddf443be

📥 Commits

Reviewing files that changed from the base of the PR and between 9f012d5 and 8ac2531.

📒 Files selected for processing (1)
  • apps/sodo-search/src/components/popup-modal.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/sodo-search/src/components/popup-modal.js

Walkthrough

The change updates keyboard handling in the popup modal component: the handler was renamed from keyUphandler to keyDownHandler, keyup listeners were replaced with keydown listeners, and the handler now ignores IME composition when event.isComposing is true or event.keyCode === 229. The effect captures containerRef?.current?.ownerDocument into a local doc variable and adds/removes the keydown listener on that doc (cleanup removes keyDownHandler). Existing arrow/enter navigation logic is preserved.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing a bug where CJK IME composition interferes with search navigation.
Description check ✅ Passed The description is well-related to the changeset, explaining the issue, root cause, solution, and providing before/after demos of the fix.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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
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)
apps/sodo-search/src/components/popup-modal.js (1)

546-551: Consider adding a guard before navigation.

If selectedResultData or its url is undefined (e.g., during a race condition when results update), this would navigate to "undefined". This is pre-existing behavior but could be hardened:

🛡️ Proposed defensive guard
 if (event.key === 'Enter') {
     const selectedResultData = allResults.find((d) => {
         return d.id === selectedResult;
     });
-    window.location.href = selectedResultData?.url;
+    if (selectedResultData?.url) {
+        window.location.href = selectedResultData.url;
+    }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/sodo-search/src/components/popup-modal.js` around lines 546 - 551, Add a
defensive guard before navigating when Enter is pressed: in the Enter key
handler that looks up selectedResultData from allResults using selectedResult,
verify that selectedResultData exists and that selectedResultData.url is a
non-empty string before assigning window.location.href; if the guard fails, do
nothing (or optionally show a fallback/error) to avoid navigating to
"undefined". Ensure you update the block containing the Enter key check and
references to selectedResultData, allResults, selectedResult, and
window.location.href.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/sodo-search/src/components/popup-modal.js`:
- Around line 546-551: Add a defensive guard before navigating when Enter is
pressed: in the Enter key handler that looks up selectedResultData from
allResults using selectedResult, verify that selectedResultData exists and that
selectedResultData.url is a non-empty string before assigning
window.location.href; if the guard fails, do nothing (or optionally show a
fallback/error) to avoid navigating to "undefined". Ensure you update the block
containing the Enter key check and references to selectedResultData, allResults,
selectedResult, and window.location.href.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 280466bf-cdb4-43c0-888d-4647c19c6760

📥 Commits

Reviewing files that changed from the base of the PR and between 832456d and 70d9bf8.

📒 Files selected for processing (1)
  • apps/sodo-search/src/components/popup-modal.js

@sailor95 sailor95 force-pushed the fix/sodo-search-ime-composition-enter branch 2 times, most recently from 866ecec to 9f012d5 Compare March 18, 2026 17:11
@cursor
Copy link

cursor bot commented Mar 18, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

When typing CJK characters (Chinese, Japanese, Korean) in the search modal,
pressing Enter to confirm an IME character selection would incorrectly navigate
to the first search result. Switched the keyboard handler from keyup to keydown
where event.isComposing reliably reflects the composition state.
@sailor95 sailor95 force-pushed the fix/sodo-search-ime-composition-enter branch from 9f012d5 to 8ac2531 Compare March 19, 2026 02:19
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