Skip to content

fix(window): defer initial tab focus until the window is activated - #3608

Open
smcho-kr wants to merge 1 commit into
wavetermdev:mainfrom
smcho-kr:fix/windows-ime-first-composition
Open

smcho-kr wants to merge 1 commit into
wavetermdev:mainfrom
smcho-kr:fix/windows-ime-first-composition

Conversation

@smcho-kr

Copy link
Copy Markdown

Problem

On Windows, typing Korean immediately after launching Wave (before clicking anywhere) draws the composition string twice: once at the caret, and once at the top-left corner of the window. Clicking outside the window and back makes it go away.

The caret copy is xterm's .composition-view — measured over CDP it sits exactly on the caret (138,114), so it is not the culprit.

Enumerating Win32 windows during the first real composition showed what is:

focus        Chrome_WidgetWin_1  Wave.exe  pid=22568  tid=19584
origin-show  CiceroUIWndFrame    Wave.exe  pid=22568  tid=19584  rect=(0, 0, 53, 31)

CiceroUIWndFrame is the TSF composition window, owned by Wave's own UI thread, parked at the screen origin.

Cause

setTabViewIntoWindow() focuses the tab's webContents right after initialization — while the host window is still hidden (show: false, it is shown later by relaunchBrowserWindows()). On Windows that races window activation (WM_ACTIVATE) against Chromium assigning the initial text-input focus. When the race is lost the TSF document manager / caret is never bound to the real widget, so Windows keeps drawing the composition window at (0, 0). Deactivating and re-activating the window re-creates the input context, which is why the manual workaround worked.

webContents.focus() called after show() does not fix it — the wrong ordering already happened; the focus has to be deferred, not repeated.

Fix

  • emain/emain-window.ts: on Windows, if the window is not visible yet, wait for its first native focus event before focusing the active tab. Visible windows (tab switches) and other platforms focus immediately, as before. The existing 10/30 ms refocus retries are kept, now shared by both paths.
  • frontend/app/view/term/termwrap.ts + xterm.css: tag xterm's hidden textarea with wave-windows-ime-anchor on Windows so it has an in-bounds 1x1 box before xterm positions it on the first cursor movement. Without it the textarea is 0x0 off-screen, which gives IME nothing to anchor to.

Testing

  • Reproduced with the old ordering on Windows 11 + Microsoft Korean IME: composition string at (0, 0) every launch.
  • A build with only the textarea anchor still reproduced the window, so the anchor alone is not the fix.
  • With the focus ordering: Win32 enumeration no longer finds a CiceroUIWndFrame at the origin on repeated launches, and the reporter confirmed normal Korean input on the shipped build.
  • Existing tab switches and multi-window behaviour are unchanged (the deferred path only applies to a window that is not visible yet, which is only the startup window).

Notes

Windows-only; macOS/Linux take the old immediate-focus path.

The active tab was focused while its host window was still hidden. On
Windows this races window activation (WM_ACTIVATE) against Chromium
assigning the text-input focus. When the race is lost, the TSF
composition window is never moved from the screen origin, so typing
Korean right after launch draws the composition string at the top-left
corner in addition to the caret. Clicking outside the window and back
re-created the input context, which is why it looked like a focus bug.

Focus the active tab on the window's first native focus event instead,
and give the hidden xterm textarea an in-bounds anchor so Windows has a
usable caret rect before xterm positions the textarea on cursor movement.

Evidence: enumerating Win32 windows during the first real composition
showed a CiceroUIWndFrame owned by the Wave UI thread at rect (0,0,53,31),
while the xterm preedit overlay was measured at the caret (138,114). A
build with only the textarea anchor still reproduced the window; adding
the focus ordering made it disappear.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Tab focus now waits for the next window focus event when a Windows window is hidden. The focus callback checks window and tab state and retries focus under specified conditions. On Windows, the terminal textarea receives the wave-windows-ime-anchor class, which has a CSS rule for its position and minimum dimensions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 36dec

This change fixes where the Windows Korean IME composition string appears at startup by deferring initial tab focus until the window is activated. The behavior change is limited to Windows hidden-window startup and a CSS anchor on the terminal textarea. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: on Windows, the initial tab focus in a hidden window is deferred until the window is activated. It uses the conventional fix(scope) format and is specific enough for a…
Description check Passed The description explains the Windows Korean IME composition bug, its root cause (focusing the tab while the window is hidden), the fix in emain-window.ts and the termwrap.ts/xterm.css anchor, and the …
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.
Full details: Title check

Explanation

The title names the main change: on Windows, the initial tab focus in a hidden window is deferred until the window is activated. It uses the conventional fix(scope) format and is specific enough for a teammate scanning history. The title does not mention the secondary xterm textarea anchor, which is an acceptable omission.

Full details: Description check

Explanation

The description explains the Windows Korean IME composition bug, its root cause (focusing the tab while the window is hidden), the fix in emain-window.ts and the termwrap.ts/xterm.css anchor, and the testing performed. It matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80660ab7-e616-413b-b703-61e46ece3a20
Commits

Reviewing files that changed from the base of the PR and between 9f1c967 and 36dec70.

Files selected for processing: 3

  • emain/emain-window.ts
  • frontend/app/view/term/termwrap.ts
  • frontend/app/view/term/xterm.css

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
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