diff options
| author | ChihGodlee <61595521+ChihGodlee@users.noreply.github.com> | 2026-05-20 20:05:38 +0800 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-05-21 03:10:52 +0300 |
| commit | 6172275252f5f724d874163462f5394800f8d55b (patch) | |
| tree | 86ff28c99faf9e20b74a75ee0abcd503e44e06db /src/server/render_stream.rs | |
| parent | d1576ade07a7236996869d78f37a4aee00367b42 (diff) | |
feat(experimental): add reveal_hidden_cursor_for_cjk_ime opt-in for CJK IME tracking
When the focused pane requests ?25l (cursor hidden) but paints its own
cursor — common in TUIs like Claude Code, pi, and codex — macOS native
input methods stop tracking the candidate-window position. CJK users
(Chinese / Japanese / Korean) cannot see candidate windows follow as
they type. Setting [experimental] reveal_hidden_cursor_for_cjk_ime = true
exposes the focused pane's cursor anchor to the outer terminal regardless
of the pane's hidden-cursor request, restoring IME tracking for CJK input.
[experimental] cjk_ime_agents is an optional allow-list. When empty,
the reveal applies to any focused pane. When non-empty (e.g.
["claude", "codex"]), the reveal only applies if the focused pane's
detected agent matches one of the listed names. This lets users enable
the workaround only for AI-agent TUIs that paint their own cursor,
leaving plain shells and other programs untouched. Accepted names: pi,
claude, codex, gemini, cursor, cline, opencode, copilot, kimi, kiro,
droid, amp, grok, hermes. Unknown names are ignored.
When the pane reports no cursor position (cursor_state returns None for
some TUIs), the anchor falls back to the pane's top-left so a stable
IME hint is always available.
[experimental] cjk_ime_cursor_shape (default "steady_block") controls
the DECSCUSR shape rendered for the revealed cursor; six variants are
accepted: block, steady_block, underline, steady_underline, bar,
steady_bar.
Trade-off when enabled: a hardware cursor will be visible in the outer
terminal for apps that hide the cursor without painting a replacement.
Default false preserves the behavior set in 2c95071. Pair the reveal
with cjk_ime_agents to scope it to specific TUIs.
Manually verified on macOS 26.5 aarch64 with system Pinyin IME against
Claude Code: candidate window tracks cursor with flag enabled, returns
to anchored-at-start behavior with flag disabled.
refs #149
Diffstat (limited to 'src/server/render_stream.rs')
| -rw-r--r-- | src/server/render_stream.rs | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/src/server/render_stream.rs b/src/server/render_stream.rs index d82eb855..6dd4ad48 100644 --- a/src/server/render_stream.rs +++ b/src/server/render_stream.rs @@ -322,11 +322,54 @@ fn focused_terminal_cursor(app_state: &AppState) -> Option<CursorState> { .iter() .find(|info| info.is_focused)?; let rt = app_state.runtime_for_pane_in_workspace(ws_idx, info.id)?; - let cursor = rt.cursor_state(info.inner_rect, true)?; - Some(CursorState { - x: cursor.x, - y: cursor.y, - visible: cursor.visible && !crate::ui::pane_is_scrolled_back(rt), - shape: cursor.shape, - }) + let scrolled_back = crate::ui::pane_is_scrolled_back(rt); + + // Determine whether the IME-anchor reveal applies to this focused pane. + // The master switch must be on, and either no agent filter is configured + // (apply to any pane) or the focused pane's detected agent matches the + // allow-list. + let reveal = app_state.reveal_hidden_cursor_for_cjk_ime + && (app_state.cjk_ime_agents.is_empty() || { + let detected = app_state + .workspaces + .get(ws_idx) + .and_then(|ws| ws.terminal_id(info.id)) + .and_then(|tid| app_state.terminals.get(tid)) + .and_then(|t| t.detected_agent); + detected.is_some_and(|agent| app_state.cjk_ime_agents.contains(&agent)) + }); + + if let Some(cursor) = rt.cursor_state(info.inner_rect, true) { + // When the reveal applies, expose the cursor anchor regardless of the + // pane's `?25l` request so macOS IMEs keep tracking the candidate + // window when TUIs paint their own cursor. Scrollback suppression + // still applies. + let visible = if reveal { + !scrolled_back + } else { + cursor.visible && !scrolled_back + }; + Some(CursorState { + x: cursor.x, + y: cursor.y, + visible, + shape: if reveal && visible { + app_state.cjk_ime_cursor_shape + } else { + cursor.shape + }, + }) + } else if reveal && !scrolled_back { + // cursor_state() returned None — the viewport has no cursor position + // (can happen with complex TUIs). Fall back to the pane's top-left so + // the outer terminal still exposes a cursor anchor for IME tracking. + Some(CursorState { + x: info.inner_rect.x, + y: info.inner_rect.y, + visible: true, + shape: app_state.cjk_ime_cursor_shape, + }) + } else { + None + } } |
