From 43614f001535fa705c3d9bc5f7698e2fd6800bc4 Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 13:20:51 +0800 Subject: [PATCH 1/9] wip(terminal): drop static special-key table, add app-cursor reader The static bindings for arrows/Home/End/PageUp/PageDown/Insert/Delete and F1-F12 can only ever send the unmodified CSI forms, so they would shadow the mode-aware encoder this branch adds; remove them here first. Also add TerminalSession::app_cursor_mode() reading DECCKM through a try-lock. --- crabport-core/src/keybind.rs | 189 +----------------------------- crabport-terminal/src/terminal.rs | 13 ++ 2 files changed, 19 insertions(+), 183 deletions(-) diff --git a/crabport-core/src/keybind.rs b/crabport-core/src/keybind.rs index e689612..86cec38 100644 --- a/crabport-core/src/keybind.rs +++ b/crabport-core/src/keybind.rs @@ -47,11 +47,6 @@ pub fn default_bindings() -> Vec { ..Modifiers::default() }; - let shift = Modifiers { - shift: true, - ..Modifiers::default() - }; - let ctrl_shift = Modifiers { control: true, shift: true, @@ -63,11 +58,6 @@ pub fn default_bindings() -> Vec { ..Modifiers::default() }; - let alt = Modifiers { - alt: true, - ..Modifiers::default() - }; - vec![ // ---- Platform shortcuts (GUI, not sent to PTY) ---- Binding { @@ -128,6 +118,7 @@ pub fn default_bindings() -> Vec { binding_ctrl("y", 0x19), binding_ctrl("z", 0x1a), // Ctrl+other keys + // ---- Ctrl+other keys ---- Binding { modifiers: ctrl, key: "space", @@ -169,179 +160,11 @@ pub fn default_bindings() -> Vec { key: "escape", action: KeyAction::Bytes(vec![0x1b]), }, - // ---- Cursor keys ---- - Binding { - modifiers: Modifiers::default(), - key: "up", - action: KeyAction::Bytes(b"\x1b[A".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "down", - action: KeyAction::Bytes(b"\x1b[B".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "right", - action: KeyAction::Bytes(b"\x1b[C".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "left", - action: KeyAction::Bytes(b"\x1b[D".to_vec()), - }, - Binding { - modifiers: shift, - key: "up", - action: KeyAction::Bytes(b"\x1b[1;2A".to_vec()), - }, - Binding { - modifiers: shift, - key: "down", - action: KeyAction::Bytes(b"\x1b[1;2B".to_vec()), - }, - Binding { - modifiers: shift, - key: "right", - action: KeyAction::Bytes(b"\x1b[1;2C".to_vec()), - }, - Binding { - modifiers: shift, - key: "left", - action: KeyAction::Bytes(b"\x1b[1;2D".to_vec()), - }, - Binding { - modifiers: alt, - key: "up", - action: KeyAction::Bytes(b"\x1b[1;3A".to_vec()), - }, - Binding { - modifiers: alt, - key: "down", - action: KeyAction::Bytes(b"\x1b[1;3B".to_vec()), - }, - Binding { - modifiers: alt, - key: "right", - action: KeyAction::Bytes(b"\x1b[1;3C".to_vec()), - }, - Binding { - modifiers: alt, - key: "left", - action: KeyAction::Bytes(b"\x1b[1;3D".to_vec()), - }, - Binding { - modifiers: ctrl, - key: "up", - action: KeyAction::Bytes(b"\x1b[1;5A".to_vec()), - }, - Binding { - modifiers: ctrl, - key: "down", - action: KeyAction::Bytes(b"\x1b[1;5B".to_vec()), - }, - Binding { - modifiers: ctrl, - key: "right", - action: KeyAction::Bytes(b"\x1b[1;5C".to_vec()), - }, - Binding { - modifiers: ctrl, - key: "left", - action: KeyAction::Bytes(b"\x1b[1;5D".to_vec()), - }, - // ---- Home / End / PageUp / PageDown / Insert / Delete ---- - Binding { - modifiers: Modifiers::default(), - key: "home", - action: KeyAction::Bytes(b"\x1b[H".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "end", - action: KeyAction::Bytes(b"\x1b[F".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "pageup", - action: KeyAction::Bytes(b"\x1b[5~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "pagedown", - action: KeyAction::Bytes(b"\x1b[6~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "insert", - action: KeyAction::Bytes(b"\x1b[2~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "delete", - action: KeyAction::Bytes(b"\x1b[3~".to_vec()), - }, - // ---- Function keys ---- - Binding { - modifiers: Modifiers::default(), - key: "f1", - action: KeyAction::Bytes(b"\x1bOP".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f2", - action: KeyAction::Bytes(b"\x1bOQ".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f3", - action: KeyAction::Bytes(b"\x1bOR".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f4", - action: KeyAction::Bytes(b"\x1bOS".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f5", - action: KeyAction::Bytes(b"\x1b[15~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f6", - action: KeyAction::Bytes(b"\x1b[17~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f7", - action: KeyAction::Bytes(b"\x1b[18~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f8", - action: KeyAction::Bytes(b"\x1b[19~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f9", - action: KeyAction::Bytes(b"\x1b[20~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f10", - action: KeyAction::Bytes(b"\x1b[21~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f11", - action: KeyAction::Bytes(b"\x1b[23~".to_vec()), - }, - Binding { - modifiers: Modifiers::default(), - key: "f12", - action: KeyAction::Bytes(b"\x1b[24~".to_vec()), - }, + // Cursor keys, Home/End, PageUp/PageDown, Insert/Delete and F1–F12 + // are encoded by [`encode_special_key`] at keypress time, so they can + // follow the program's DECCKM mode and the xterm modifier encoding — + // a static table can only ever send the unmodified CSI forms, which + // is what made the cursor keys wrong inside vim/less. ] } diff --git a/crabport-terminal/src/terminal.rs b/crabport-terminal/src/terminal.rs index 5117e3c..fd6c5d9 100644 --- a/crabport-terminal/src/terminal.rs +++ b/crabport-terminal/src/terminal.rs @@ -1164,6 +1164,19 @@ impl TerminalSession { self.kitty_keyboard.load(Ordering::SeqCst) != 0 } + /// Whether the running program has enabled DECCKM (`\x1b[?1h`), the + /// application-cursor-keys mode that vim/less/nano switch into. Arrow and + /// Home/End keys must then use the SS3 forms (`ESC O A`, `ESC O H`) + /// instead of the CSI forms. + /// + /// Reads through a try-lock: a keypress that lands while the PTY thread + /// holds the term lock encodes the normal CSI form rather than stalling + /// input. + pub fn app_cursor_mode(&self) -> bool { + self.try_with_term_mut(|term| term.mode().contains(TermMode::APP_CURSOR)) + .unwrap_or(false) + } + /// Scan a chunk of *program output* for kitty-keyboard negotiation /// requests and react accordingly. /// From 0b561205a6d638cefc8ff46463b0416a489ab63a Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 13:17:49 +0800 Subject: [PATCH 2/9] fix(terminal): encode Ctrl+ as the xterm control byte (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keys with Ctrl held that no binding covers fell through to nothing: gpui leaves key_char unset whenever Ctrl is held, and reports the shifted character as the key name with shift cleared, so Ctrl+Shift+- arrives as key = "_" — a name no binding matched, and the IME path never sees control keydowns. nano's go-to-line (^_) was unreachable. Map the key name through the xterm control table as a fallback after binding resolution (a-z -> 0x01..0x1a, @ [ \ ] ^ _ -> 0x00..0x1f, ? -> 0x7f); undefined keys (-, /, digits) still fall through unchanged, and an active IME composition is never intercepted. --- crabport-core/src/keybind.rs | 120 ++++++++++++++++++++++++++++++ crabport-ui/src/views/terminal.rs | 23 +++++- 2 files changed, 142 insertions(+), 1 deletion(-) diff --git a/crabport-core/src/keybind.rs b/crabport-core/src/keybind.rs index 86cec38..9a8ada1 100644 --- a/crabport-core/src/keybind.rs +++ b/crabport-core/src/keybind.rs @@ -211,3 +211,123 @@ pub fn resolve<'a>(keystroke: &Keystroke, bindings: &'a [Binding]) -> Option<&'a }) .map(|b| &b.action) } + +#[cfg(test)] +mod tests { + use super::*; + + fn key(key: &str, m: Modifiers) -> Keystroke { + Keystroke { + key: key.to_owned(), + key_char: None, + modifiers: m, + } + } + + fn ctrl() -> Modifiers { + Modifiers { + control: true, + ..Modifiers::default() + } + } + + #[test] + fn letters_map_to_their_control_byte() { + assert_eq!(control_byte(&key("c", ctrl())), Some(0x03)); + assert_eq!(control_byte(&key("u", ctrl())), Some(0x15)); + assert_eq!(control_byte(&key("z", ctrl())), Some(0x1a)); + } + + /// #88: gpui reports `Ctrl+Shift+-` as `key = "_"` with `shift` cleared, + /// so the key name is what has to map, and it must become US (0x1f) — + /// nano's go-to-line. + #[test] + fn shifted_punctuation_maps_by_its_key_name() { + assert_eq!(control_byte(&key("_", ctrl())), Some(0x1f)); + assert_eq!(control_byte(&key("[", ctrl())), Some(0x1b)); + assert_eq!(control_byte(&key("\\", ctrl())), Some(0x1c)); + assert_eq!(control_byte(&key("]", ctrl())), Some(0x1d)); + assert_eq!(control_byte(&key("^", ctrl())), Some(0x1e)); + assert_eq!(control_byte(&key("@", ctrl())), Some(0x00)); + } + + #[test] + fn question_mark_is_del_not_us() { + assert_eq!(control_byte(&key("?", ctrl())), Some(0x7f)); + } + + #[test] + fn undefined_keys_fall_through() { + // `-` without Shift has no control byte (sending CR here would act + // like Enter in the shell). + assert_eq!(control_byte(&key("-", ctrl())), None); + assert_eq!(control_byte(&key("/", ctrl())), None); + assert_eq!(control_byte(&key("1", ctrl())), None); + } + + #[test] + fn other_modifiers_never_map() { + let mut m = ctrl(); + m.platform = true; + assert_eq!(control_byte(&key("_", m)), None); + + let mut m = ctrl(); + m.alt = true; + assert_eq!(control_byte(&key("_", m)), None); + + let mut m = ctrl(); + m.function = true; + assert_eq!(control_byte(&key("_", m)), None); + + // Without Ctrl there is nothing to map. + assert_eq!(control_byte(&key("_", Modifiers::default())), None); + } + + #[test] + fn multi_character_and_named_keys_do_not_map() { + assert_eq!(control_byte(&key("home", ctrl())), None); + assert_eq!(control_byte(&key("ab", ctrl())), None); + } +} + +/// The control byte xterm would send for a key with `Ctrl` held and no ⌘, +/// Option or Fn — the xterm/ECMA-48 control-character table: +/// +/// | key | byte | key | byte | +/// | --- | --- | --- | --- | +/// | `a`–`z` | 0x01–0x1a | `@` `[` `\` `]` `^` `_` | 0x00–0x1f | +/// | `?` | 0x7f (DEL) | | | +/// +/// Keys outside that table (`-`, `/`, digits, …) have no defined control +/// byte and yield `None`, so the key falls through unchanged. +/// +/// This reads `key`, not `key_char`: gpui leaves `key_char` unset whenever +/// Ctrl is held, and reports the shifted character as the key name with +/// `shift` cleared — `Ctrl+Shift+-` arrives as `key = "_"` — so a binding +/// named `ctrl-shift--` could never match and the key was silently dropped +/// (#88). `Ctrl+_` and therefore `Ctrl+Shift+-` now send US (0x1f), which is +/// nano's go-to-line. +pub fn control_byte(keystroke: &Keystroke) -> Option { + let m = &keystroke.modifiers; + if !m.control || m.platform || m.alt || m.function { + return None; + } + let mut chars = keystroke.key.chars(); + let (c, single) = match (chars.next(), chars.next()) { + (Some(c), None) => (c, true), + _ => return None, + }; + if !single { + return None; + } + let lower = c.to_ascii_lowercase() as u8; + match lower { + // Ctrl+A–Z → 0x01–0x1a. + b'a'..=b'z' => Some(lower - b'a' + 0x01), + // Ctrl+@ [ \ ] ^ _ → 0x00–0x1f. + b'@'..=b'_' => Some(lower - b'@'), + // Ctrl+? is DEL, not US: 0x1f already belongs to Ctrl+_. + b'?' => Some(0x7f), + _ => None, + } +} diff --git a/crabport-ui/src/views/terminal.rs b/crabport-ui/src/views/terminal.rs index c67c7c3..c641050 100644 --- a/crabport-ui/src/views/terminal.rs +++ b/crabport-ui/src/views/terminal.rs @@ -2389,7 +2389,28 @@ impl Render for TerminalView { // and we don't want the IME to swallow or echo them. cx.stop_propagation(); } - None => {} + None => { + // Keys with Ctrl held that no binding covers fall + // through to the xterm control-byte table (#88): + // `Ctrl+Shift+-` arrives from gpui as `key = "_"` with + // `shift` cleared and `key_char` unset, so nothing + // above can match it, and the IME path never sees + // control keydowns either. Skipped while an IME + // composition is active so editing keys still reach + // the input context. + let composing = this + .marked_text + .lock() + .as_ref() + .map(|s| !s.is_empty()) + .unwrap_or(false); + if !composing && let Some(byte) = keybind::control_byte(&event.keystroke) { + this.session.write(&[byte]); + this.session.scroll_to_bottom(); + cx.notify(); + cx.stop_propagation(); + } + } } })) .child( From 064944b9990f67ddbcf24434f53142b0ebdcf83e Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 13:27:59 +0800 Subject: [PATCH 3/9] feat(terminal): mode-aware special keys for full-screen programs The static table for arrows/Home/End/PageUp/PageDown/Insert/Delete and F1-F12 could only ever send the unmodified CSI forms. Two gaps in full-screen programs (vim, less, htop): - DECCKM: once a program enables application cursor keys (ESC [ ? 1 h), the unmodified cursor keys and Home/End must use the SS3 forms (ESC O A, ESC O H). Everything kept sending CSI, so vim moved by sentences and less scrolled wrong. - Modifiers: Shift/Ctrl/Alt combinations of those keys were dropped entirely; xterm encodes them as CSI 1;{m}X / CSI {n};{m}~. Replace the static table with keybind::encode_special_key(), which takes the program's DECCKM state (TerminalSession::app_cursor_mode(), read through a try-lock) and the xterm modifier parameter (1 + shift + 2*alt + 4*ctrl). F1-F4 use SS3 unmodified and CSI with modifiers; the ~-form keys ignore DECCKM. Cmd-chords stay with the app, matching the kitty-protocol path. --- crabport-core/src/keybind.rs | 240 ++++++++++++++++++++++++++++++ crabport-ui/src/views/terminal.rs | 46 ++++-- 2 files changed, 275 insertions(+), 11 deletions(-) diff --git a/crabport-core/src/keybind.rs b/crabport-core/src/keybind.rs index 9a8ada1..47938d3 100644 --- a/crabport-core/src/keybind.rs +++ b/crabport-core/src/keybind.rs @@ -212,6 +212,92 @@ pub fn resolve<'a>(keystroke: &Keystroke, bindings: &'a [Binding]) -> Option<&'a .map(|b| &b.action) } +/// The xterm modifier parameter for a key event: `1 + shift + 2*alt + 4*ctrl`. +/// `1` is the protocol's "no modifier" value. +fn modifier_parameter(m: &Modifiers) -> u8 { + 1 + (m.shift as u8) + 2 * (m.alt as u8) + 4 * (m.control as u8) +} + +/// Encode a special (non-text) key the way xterm does, honouring the +/// program's DECCKM mode and the xterm modifier encoding: +/// +/// - Arrow, Home and End use the CSI forms (`ESC [ A`, `ESC [ H`) in normal +/// mode and the SS3 forms (`ESC O A`, `ESC O H`) once the program enables +/// DECCKM (`ESC [ ? 1 h`) — what vim/less do at startup. +/// - With a modifier held, xterm switches to the parameterised CSI form +/// (`ESC [ 1;5C` for Ctrl+Right), so DECCKM no longer applies. F1–F4 use +/// SS3 unmodified (`ESC O P`) and CSI with modifiers (`ESC [ 1;2P`). +/// - PageUp/PageDown, Insert/Delete and F5–F12 are `~`-form sequences and are +/// unaffected by DECCKM. +/// +/// Returns `None` for every other key, and when ⌘ is held (⌘ shortcuts stay +/// with the application, as the kitty-protocol path already does). +pub fn encode_special_key(key: &str, mods: &Modifiers, app_cursor: bool) -> Option> { + if mods.platform || mods.function { + return None; + } + let m = modifier_parameter(mods); + + let seq = match key { + "up" => cursor('A', m, app_cursor), + "down" => cursor('B', m, app_cursor), + "right" => cursor('C', m, app_cursor), + "left" => cursor('D', m, app_cursor), + "home" => cursor('H', m, app_cursor), + "end" => cursor('F', m, app_cursor), + "pageup" => tilde(5, m), + "pagedown" => tilde(6, m), + "insert" => tilde(2, m), + "delete" => tilde(3, m), + "f1" => function('P', m), + "f2" => function('Q', m), + "f3" => function('R', m), + "f4" => function('S', m), + "f5" => tilde(15, m), + "f6" => tilde(17, m), + "f7" => tilde(18, m), + "f8" => tilde(19, m), + "f9" => tilde(20, m), + "f10" => tilde(21, m), + "f11" => tilde(23, m), + "f12" => tilde(24, m), + _ => return None, + }; + Some(seq.into_bytes()) +} + +/// One of the cursor-family keys: CSI `X` (or SS3 `X` in application mode) +/// unmodified, parameterised CSI with a modifier held. +fn cursor(final_byte: char, m: u8, app_cursor: bool) -> String { + if m == 1 { + if app_cursor { + format!("\x1bO{final_byte}") + } else { + format!("\x1b[{final_byte}") + } + } else { + format!("\x1b[1;{m}{final_byte}") + } +} + +/// One of the `~`-form keys (PageUp/PageDown, Insert/Delete, F5–F12). +fn tilde(number: u8, m: u8) -> String { + if m == 1 { + format!("\x1b[{number}~") + } else { + format!("\x1b[{number};{m}~") + } +} + +/// F1–F4: SS3 unmodified, parameterised CSI with a modifier held. +fn function(final_byte: char, m: u8) -> String { + if m == 1 { + format!("\x1bO{final_byte}") + } else { + format!("\x1b[1;{m}{final_byte}") + } +} + #[cfg(test)] mod tests { use super::*; @@ -288,6 +374,160 @@ mod tests { assert_eq!(control_byte(&key("home", ctrl())), None); assert_eq!(control_byte(&key("ab", ctrl())), None); } + + fn shift() -> Modifiers { + Modifiers { + shift: true, + ..Modifiers::default() + } + } + + fn alt() -> Modifiers { + Modifiers { + alt: true, + ..Modifiers::default() + } + } + + // ----------------------------------------------------------------- + // encode_special_key + // ----------------------------------------------------------------- + + #[test] + fn arrows_use_csi_outside_application_mode() { + assert_eq!( + encode_special_key("up", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[A".as_slice()) + ); + assert_eq!( + encode_special_key("down", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[B".as_slice()) + ); + assert_eq!( + encode_special_key("right", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[C".as_slice()) + ); + assert_eq!( + encode_special_key("left", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[D".as_slice()) + ); + } + + /// In vim/less (DECCKM on) the unmodified cursor keys must use the SS3 + /// forms, and Home/End follow the same rule. + #[test] + fn application_mode_switches_to_ss3() { + assert_eq!( + encode_special_key("up", &Modifiers::default(), true).as_deref(), + Some(b"\x1bOA".as_slice()) + ); + assert_eq!( + encode_special_key("left", &Modifiers::default(), true).as_deref(), + Some(b"\x1bOD".as_slice()) + ); + assert_eq!( + encode_special_key("home", &Modifiers::default(), true).as_deref(), + Some(b"\x1bOH".as_slice()) + ); + assert_eq!( + encode_special_key("end", &Modifiers::default(), true).as_deref(), + Some(b"\x1bOF".as_slice()) + ); + } + + #[test] + fn modifiers_use_the_parameterised_csi_form_even_in_application_mode() { + // 1 + shift = 2. + assert_eq!( + encode_special_key("up", &shift(), false).as_deref(), + Some(b"\x1b[1;2A".as_slice()) + ); + // 1 + alt = 3. + assert_eq!( + encode_special_key("left", &alt(), true).as_deref(), + Some(b"\x1b[1;3D".as_slice()) + ); + // 1 + ctrl = 5. + assert_eq!( + encode_special_key("right", &ctrl(), false).as_deref(), + Some(b"\x1b[1;5C".as_slice()) + ); + // 1 + shift + ctrl = 6. + let mut m = ctrl(); + m.shift = true; + assert_eq!( + encode_special_key("home", &m, true).as_deref(), + Some(b"\x1b[1;6H".as_slice()) + ); + } + + #[test] + fn home_and_end_use_csi_outside_application_mode() { + assert_eq!( + encode_special_key("home", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[H".as_slice()) + ); + assert_eq!( + encode_special_key("end", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[F".as_slice()) + ); + } + + #[test] + fn tilde_keys_ignore_application_mode() { + assert_eq!( + encode_special_key("pageup", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[5~".as_slice()) + ); + assert_eq!( + encode_special_key("pagedown", &Modifiers::default(), true).as_deref(), + Some(b"\x1b[6~".as_slice()) + ); + assert_eq!( + encode_special_key("insert", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[2~".as_slice()) + ); + assert_eq!( + encode_special_key("delete", &shift(), false).as_deref(), + Some(b"\x1b[3;2~".as_slice()) + ); + } + + #[test] + fn function_keys_use_ss3_then_csi() { + assert_eq!( + encode_special_key("f1", &Modifiers::default(), false).as_deref(), + Some(b"\x1bOP".as_slice()) + ); + assert_eq!( + encode_special_key("f4", &Modifiers::default(), true).as_deref(), + Some(b"\x1bOS".as_slice()) + ); + assert_eq!( + encode_special_key("f1", &shift(), false).as_deref(), + Some(b"\x1b[1;2P".as_slice()) + ); + assert_eq!( + encode_special_key("f5", &Modifiers::default(), false).as_deref(), + Some(b"\x1b[15~".as_slice()) + ); + assert_eq!( + encode_special_key("f12", &ctrl(), false).as_deref(), + Some(b"\x1b[24;5~".as_slice()) + ); + } + + #[test] + fn cmd_shortcuts_and_unknown_keys_are_left_to_the_app() { + let mut m = Modifiers::default(); + m.platform = true; + assert_eq!(encode_special_key("up", &m, false), None); + assert_eq!( + encode_special_key("enter", &Modifiers::default(), false), + None + ); + assert_eq!(encode_special_key("a", &Modifiers::default(), false), None); + } } /// The control byte xterm would send for a key with `Ctrl` held and no ⌘, diff --git a/crabport-ui/src/views/terminal.rs b/crabport-ui/src/views/terminal.rs index c641050..d6b9cce 100644 --- a/crabport-ui/src/views/terminal.rs +++ b/crabport-ui/src/views/terminal.rs @@ -2392,23 +2392,47 @@ impl Render for TerminalView { None => { // Keys with Ctrl held that no binding covers fall // through to the xterm control-byte table (#88): - // `Ctrl+Shift+-` arrives from gpui as `key = "_"` with - // `shift` cleared and `key_char` unset, so nothing - // above can match it, and the IME path never sees - // control keydowns either. Skipped while an IME - // composition is active so editing keys still reach - // the input context. + // Keys no binding covers fall through to the xterm + // encodings: + // + // - `Ctrl+` → its control byte (#88). gpui + // leaves `key_char` unset whenever Ctrl is held, and + // reports the shifted character as the key name with + // `shift` cleared, so `Ctrl+Shift+-` arrives as + // `key = "_"` — a name no binding matched, and the + // IME path never sees control keydowns either. + // - Special keys (arrows, Home/End, PageUp/PageDown, + // Insert/Delete, F1–F12) → the xterm forms that + // follow the program's DECCKM mode and carry + // modifiers, which is what vim/less need. + // + // Skipped while an IME composition is active so + // editing keys still reach the input context. let composing = this .marked_text .lock() .as_ref() .map(|s| !s.is_empty()) .unwrap_or(false); - if !composing && let Some(byte) = keybind::control_byte(&event.keystroke) { - this.session.write(&[byte]); - this.session.scroll_to_bottom(); - cx.notify(); - cx.stop_propagation(); + if !composing { + let bytes = keybind::control_byte(&event.keystroke) + .map(|byte| vec![byte]) + .or_else(|| { + keybind::encode_special_key( + &event.keystroke.key, + &event.keystroke.modifiers, + this.session.app_cursor_mode(), + ) + }); + if let Some(bytes) = bytes { + this.session.write(&bytes); + this.session.scroll_to_bottom(); + cx.notify(); + // Stop propagation so the platform's IME input + // context doesn't also receive this keydown: + // these are control sequences, not text. + cx.stop_propagation(); + } } } } From 81b7f96d453e0ff88a808e4712f3d576d4d937fe Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 13:41:00 +0800 Subject: [PATCH 4/9] feat(terminal): explicit ways to close a split pane (#89) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The toolbar offered Split Right / Split Down but nothing to undo them: leaving a split meant typing exit in that shell. The plumbing already existed (close_pane collapses the tree, closes the tab on the last pane, and backends already auto-close their pane on exit) — what was missing was an affordance. Three entries now share that one path: - Close Pane in the terminal's right-click menu, next to Split Right / Split Down, shown only when the tab has more than one pane. - A close button beside the split buttons in the top-right toolbar row, same condition, targeting the focused pane. - Cmd-W closes the focused pane (or the tab when it is the last one), matching iTerm/Terminal muscle memory. Empty default elsewhere: Ctrl+W is 0x17 and must reach the shell. --- crabport-ui/i18n/en.toml | 1 + crabport-ui/i18n/zh-CN.toml | 1 + crabport-ui/src/app.rs | 1 + crabport-ui/src/app/tabs.rs | 55 ++++++++++++++++++++++++++++++ crabport-ui/src/keybinds.rs | 4 +++ crabport-ui/src/layouts/content.rs | 40 ++++++++++++++++++++++ crabport-ui/src/views/terminal.rs | 17 +++++++++ 7 files changed, 119 insertions(+) diff --git a/crabport-ui/i18n/en.toml b/crabport-ui/i18n/en.toml index 662fb49..7da118e 100644 --- a/crabport-ui/i18n/en.toml +++ b/crabport-ui/i18n/en.toml @@ -651,6 +651,7 @@ action_terminal_reset_font = "Terminal: Reset Font Size" action_terminal_search = "Terminal: Search" action_split_vertical = "Terminal: Split Pane Vertically" action_split_horizontal = "Terminal: Split Pane Horizontally" +action_close_pane = "Terminal: Close Pane" [menu] app_name = "CrabPort" diff --git a/crabport-ui/i18n/zh-CN.toml b/crabport-ui/i18n/zh-CN.toml index a0dc17f..37b1de8 100644 --- a/crabport-ui/i18n/zh-CN.toml +++ b/crabport-ui/i18n/zh-CN.toml @@ -652,6 +652,7 @@ action_terminal_reset_font = "终端:重置字体" action_terminal_search = "终端:搜索" action_split_vertical = "终端:垂直分割面板" action_split_horizontal = "终端:水平分割面板" +action_close_pane = "终端:关闭窗格" [menu] app_name = "CrabPort" diff --git a/crabport-ui/src/app.rs b/crabport-ui/src/app.rs index 1edda8a..0f49c57 100644 --- a/crabport-ui/src/app.rs +++ b/crabport-ui/src/app.rs @@ -78,6 +78,7 @@ actions!( TerminalSearch, SplitVertical, SplitHorizontal, + ClosePane, ] ); diff --git a/crabport-ui/src/app/tabs.rs b/crabport-ui/src/app/tabs.rs index 9dd9544..4fde688 100644 --- a/crabport-ui/src/app/tabs.rs +++ b/crabport-ui/src/app/tabs.rs @@ -932,6 +932,27 @@ impl CrabportApp { self.focus_pane_next_frame(new_pane_id, cx); } + /// The tab whose split tree contains `pane_id`, if any. + fn tab_id_for_pane(&self, pane_id: u64) -> Option { + self.split_trees + .iter() + .find(|(_, tree)| tree.root.find_pane(pane_id)) + .map(|(tab_id, _)| *tab_id) + } + + /// Close the pane that owns the keyboard focus in the active terminal + /// tab (⌘W, #89). [`Self::close_pane`] collapses the split, or closes + /// the whole tab when the pane was the last one. A no-op on tabs with + /// no split tree (Home, SFTP). + pub fn close_focused_pane(&mut self, cx: &mut Context) { + let tab_id = self.active_tab_id; + let Some(tree) = self.split_trees.get(&tab_id) else { + return; + }; + let pane_id = tree.active_pane; + self.close_pane(tab_id, pane_id, cx); + } + /// Close a single pane by pane id. If it was the last pane in the tab, /// the whole tab is closed (mirrors `close_tab`). Otherwise the split /// tree collapses and the active pane is updated. @@ -1163,6 +1184,28 @@ impl CrabportApp { }, )); + // Close Pane — collapses the split the right-clicked pane belongs + // to (#89). Only offered when the tab actually has more than one + // pane, so the item never appears where there is nothing to close: + // with a single pane, closing means closing the tab, and the tab + // bar already has a close button for that. + if let Some(pane_id) = real_pane_id + && let Some(close_tab_id) = self.tab_id_for_pane(pane_id) + && let Some(tree) = self.split_trees.get(&close_tab_id) + && tree.root.find_pane(pane_id) + && tree.root.pane_ids().len() > 1 + { + let app_for_close = cx.entity().clone(); + items.push(ContextMenuItem::new( + t!("terminal.close_pane").to_string(), + move |_w, cx| { + app_for_close.update(cx, |app, cx| { + app.close_pane(close_tab_id, pane_id, cx); + }); + }, + )); + } + // Clear Screen — erases the visible terminal display but keeps // scrollback. Equivalent to the `clear` shell command. items.push(ContextMenuItem::new( @@ -1210,6 +1253,7 @@ impl CrabportApp { let app_handle = cx.entity().downgrade(); let app_handle2 = cx.entity().downgrade(); let app_handle3 = cx.entity().downgrade(); + let app_handle4 = cx.entity().downgrade(); // Capture the view entity so the `on_focused` callback can resolve // the real pane_id (the key in `pane_views`) by entity equality. // The `pane_id` passed to the callback is `TerminalView::count`, @@ -1253,6 +1297,17 @@ impl CrabportApp { }); }); }); + v.set_on_close_request(move |cx| { + // Defer like the split callback: close_pane touches + // pane_views / split_trees and other entities, which would + // re-enter the borrow held by the on_action handler. + let h = app_handle4.clone(); + cx.defer(move |cx| { + let _ = h.update(cx, |app, cx| { + app.close_focused_pane(cx); + }); + }); + }); // Right-click inside the terminal pane surfaces a // Copy/Paste/Select-All context menu. Resolve the real pane_id // (the key in `pane_views`) by entity equality so the menu diff --git a/crabport-ui/src/keybinds.rs b/crabport-ui/src/keybinds.rs index 247953e..80edff3 100644 --- a/crabport-ui/src/keybinds.rs +++ b/crabport-ui/src/keybinds.rs @@ -108,6 +108,10 @@ pub fn catalog() -> Vec { "terminal_search" => crate::app::TerminalSearch, TERM, plat("cmd-f", "ctrl-f"), true; "split_vertical" => crate::app::SplitVertical, TERM, plat("cmd-d", "ctrl-d"), true; "split_horizontal" => crate::app::SplitHorizontal, TERM, plat("cmd-shift-d", "ctrl-shift-d"), true; + // ⌘W closes the focused pane, or the tab when it is the last one. + // Empty on other platforms: Ctrl+W is 0x17 (delete word) and must + // reach the shell. + "close_pane" => crate::app::ClosePane, TERM, plat("cmd-w", ""), true; ) } diff --git a/crabport-ui/src/layouts/content.rs b/crabport-ui/src/layouts/content.rs index 66aadaa..8e8b7a7 100644 --- a/crabport-ui/src/layouts/content.rs +++ b/crabport-ui/src/layouts/content.rs @@ -290,6 +290,7 @@ pub fn render_content( let handle_split_r = handle.clone(); let handle_split_d = handle.clone(); let handle_panel = handle.clone(); + let handle_close_pane = handle.clone(); // Read the active terminal view's search state so the search // bar can float above the split/panel buttons. let term_view = terminal_views.get(&tab_id).cloned(); @@ -456,6 +457,45 @@ pub fn render_content( } }, )) + // Close Pane — only when this tab + // actually has more than one pane; + // with one pane there is nothing to + // close (the tab bar has that + // button). Targets the focused pane, + // which is what the split buttons + // also operate on (#89). + .when( + split_trees + .get(&active_tab_id) + .is_some_and(|tree| { + tree.root.pane_ids().len() > 1 + }), + |el| { + el.child(render_split_button( + "term-close-pane", + "icons/x.svg", + t!("terminal.close_pane").to_string(), + ctx.tooltip.clone(), + { + let handle = handle_close_pane.clone(); + move |_w, cx| { + handle.update(cx, |app, cx| { + if let Some(tree) = + app.split_trees.get(&active_tab_id) + { + let pane_id = tree.active_pane; + app.close_pane( + active_tab_id, + pane_id, + cx, + ); + } + }); + } + }, + )) + }, + ) .child(render_split_button( "term-toggle-panel", "icons/panel-right.svg", diff --git a/crabport-ui/src/views/terminal.rs b/crabport-ui/src/views/terminal.rs index d6b9cce..2aea9ea 100644 --- a/crabport-ui/src/views/terminal.rs +++ b/crabport-ui/src/views/terminal.rs @@ -193,6 +193,10 @@ pub struct TerminalView { /// Invoked when the user triggers a split via keyboard shortcut. /// Receives the split direction. The app calls `split_active_pane`. on_split_request: Option>, + /// Invoked when the user asks to close this pane (⌘W). The app calls + /// `close_pane`, which collapses the split — or closes the tab when this + /// was the last pane (#89). + on_close_request: Option>, /// Invoked when the user right-clicks inside the terminal pane. /// Receives the click position (window-relative pixels) and the pane /// id, so the app can show a context menu with Copy/Paste/etc. actions @@ -643,6 +647,7 @@ impl TerminalView { on_connection_result: None, on_focused: None, on_split_request: None, + on_close_request: None, on_context_menu: None, sftp_progress: None, on_sftp_progress_changed: None, @@ -1507,6 +1512,13 @@ impl TerminalView { self.on_split_request.clone() } + /// Set the callback invoked when the user asks to close this pane + /// (⌘W). The app collapses the split the pane belongs to, or closes + /// the whole tab when this was the last pane. + pub fn set_on_close_request(&mut self, f: impl Fn(&mut App) + 'static) { + self.on_close_request = Some(Rc::new(f)); + } + /// Set the callback invoked when the user right-clicks inside this /// terminal pane. The app uses it to show a context menu with /// Copy/Paste/Select-All actions scoped to this pane. The callback @@ -2284,6 +2296,11 @@ impl Render for TerminalView { } }), ) + .on_action(cx.listener(|this, _: &crate::app::ClosePane, _window, cx| { + if let Some(cb) = &this.on_close_request { + cb(cx); + } + })) .on_action( cx.listener(|this, _: &crate::app::TerminalSearch, window, cx| { this.toggle_search(window, cx); From 532783ef112c80036a309e31fe788d65b540d3f2 Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 14:22:38 +0800 Subject: [PATCH 5/9] feat(terminal): per-pane close button in every split (#89) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the toolbar close button with one inside each pane: with more than one pane in the tab, every pane carries its own ✕ at its top-left that closes exactly that pane — a split reads (and un-reads) like a little window, instead of a global button closing whatever happens to hold focus. Placement is the top-left because the top-right corner is already taken by the global split/panel cluster, with the search bar sliding beneath it; the pane's close control sits where a traffic light would, and never collides with either. keeps the press from starting a selection in the terminal underneath, and the click bubbles through the pane's focus handler first, which is harmless: the pane closes anyway. The toolbar button is gone; the right-click Close Pane item and Cmd-W remain. --- crabport-ui/src/layouts/content.rs | 188 +++++++++++++++++++++-------- 1 file changed, 136 insertions(+), 52 deletions(-) diff --git a/crabport-ui/src/layouts/content.rs b/crabport-ui/src/layouts/content.rs index 8e8b7a7..d07286f 100644 --- a/crabport-ui/src/layouts/content.rs +++ b/crabport-ui/src/layouts/content.rs @@ -265,8 +265,17 @@ pub fn render_content( // If this tab has a split tree, render the panes recursively; // otherwise fall back to the single terminal view. let inner: AnyElement = if let Some(tree) = split_trees.get(&tab_id) { - render_split_node(&tree.root, tree.active_pane, tab_id, pane_views, handle) - .into_any_element() + let multi_pane = tree.root.pane_ids().len() > 1; + render_split_node( + &tree.root, + tree.active_pane, + multi_pane, + tab_id, + pane_views, + handle, + ctx.tooltip.clone(), + ) + .into_any_element() } else if let Some(terminal_entity) = terminal_views.get(&tab_id) { div() .size_full() @@ -290,7 +299,6 @@ pub fn render_content( let handle_split_r = handle.clone(); let handle_split_d = handle.clone(); let handle_panel = handle.clone(); - let handle_close_pane = handle.clone(); // Read the active terminal view's search state so the search // bar can float above the split/panel buttons. let term_view = terminal_views.get(&tab_id).cloned(); @@ -457,45 +465,6 @@ pub fn render_content( } }, )) - // Close Pane — only when this tab - // actually has more than one pane; - // with one pane there is nothing to - // close (the tab bar has that - // button). Targets the focused pane, - // which is what the split buttons - // also operate on (#89). - .when( - split_trees - .get(&active_tab_id) - .is_some_and(|tree| { - tree.root.pane_ids().len() > 1 - }), - |el| { - el.child(render_split_button( - "term-close-pane", - "icons/x.svg", - t!("terminal.close_pane").to_string(), - ctx.tooltip.clone(), - { - let handle = handle_close_pane.clone(); - move |_w, cx| { - handle.update(cx, |app, cx| { - if let Some(tree) = - app.split_trees.get(&active_tab_id) - { - let pane_id = tree.active_pane; - app.close_pane( - active_tab_id, - pane_id, - cx, - ); - } - }); - } - }, - )) - }, - ) .child(render_split_button( "term-toggle-panel", "icons/panel-right.svg", @@ -1079,15 +1048,24 @@ pub fn render_content( fn render_split_node( node: &SplitNode, active_pane: u64, + multi_pane: bool, tab_id: u64, pane_views: &HashMap>, handle: &Entity, + tooltip_ctrl: Entity, ) -> AnyElement { use gpui_component::resizable::{h_resizable, resizable_panel, v_resizable}; match node { - SplitNode::Pane(pane_id) => { - render_pane(*pane_id, active_pane, tab_id, pane_views, handle).into_any_element() - } + SplitNode::Pane(pane_id) => render_pane( + *pane_id, + active_pane, + multi_pane, + tab_id, + pane_views, + handle, + tooltip_ctrl, + ) + .into_any_element(), SplitNode::Split { dir, a, b, .. } => { let dir = *dir; let group_id = @@ -1098,8 +1076,24 @@ fn render_split_node( }; // Render children. For a nested split child, wrap it in a // `resizable_panel` so the inner group fills its allocated space. - let child_a = render_split_child(a, active_pane, tab_id, pane_views, handle); - let child_b = render_split_child(b, active_pane, tab_id, pane_views, handle); + let child_a = render_split_child( + a, + active_pane, + multi_pane, + tab_id, + pane_views, + handle, + tooltip_ctrl.clone(), + ); + let child_b = render_split_child( + b, + active_pane, + multi_pane, + tab_id, + pane_views, + handle, + tooltip_ctrl, + ); let group = if axis == gpui::Axis::Horizontal { h_resizable(group_id) @@ -1119,28 +1113,49 @@ fn render_split_node( fn render_split_child( node: &SplitNode, active_pane: u64, + multi_pane: bool, tab_id: u64, pane_views: &HashMap>, handle: &Entity, + tooltip_ctrl: Entity, ) -> AnyElement { match node { - SplitNode::Pane(pane_id) => { - render_pane(*pane_id, active_pane, tab_id, pane_views, handle).into_any_element() - } + SplitNode::Pane(pane_id) => render_pane( + *pane_id, + active_pane, + multi_pane, + tab_id, + pane_views, + handle, + tooltip_ctrl, + ) + .into_any_element(), SplitNode::Split { .. } => { // Nested split: render as a group, which itself becomes the child. - render_split_node(node, active_pane, tab_id, pane_views, handle) + render_split_node( + node, + active_pane, + multi_pane, + tab_id, + pane_views, + handle, + tooltip_ctrl, + ) } } } -/// Render a single terminal pane with click-to-focus + active highlight. +/// Render a single terminal pane with click-to-focus + active highlight, +/// and — when the tab holds more than one pane — its own close button +/// (#89): every split pane closes itself, like a little window. fn render_pane( pane_id: u64, active_pane: u64, + multi_pane: bool, tab_id: u64, pane_views: &HashMap>, handle: &Entity, + tooltip_ctrl: Entity, ) -> impl IntoElement { let is_active = pane_id == active_pane; let view = pane_views.get(&pane_id).cloned(); @@ -1149,6 +1164,7 @@ fn render_pane( .id(ElementId::Name( format!("pane-{}-{}", tab_id, pane_id).into(), )) + .relative() .size_full() // Occlude so this pane's hitbox blocks sibling panes' mouse // handlers — without this, overlapping hitboxes (e.g. when the @@ -1173,9 +1189,77 @@ fn render_pane( if let Some(view) = view { el = el.child(view); } + if multi_pane { + el = el.child(render_pane_close_button( + pane_id, + tab_id, + handle.clone(), + tooltip_ctrl, + )); + } el } +/// The per-pane close button (#89). Sits at the pane's top-left: the +/// top-right corner is occupied by the global split/panel cluster (and the +/// search bar that slides beneath it), so a top-left control reads like a +/// little window's traffic light and never collides with it. `.occlude()` +/// keeps the press from starting a selection in the terminal below. +fn render_pane_close_button( + pane_id: u64, + tab_id: u64, + handle: Entity, + tooltip_ctrl: Entity, +) -> impl IntoElement { + let btn_id = ElementId::Name(format!("pane-close-{}-{}", tab_id, pane_id).into()); + let hover_bg = rgba((surface_hover() << 8) | 0xFF); + let rest_bg = rgba((surface_hover() << 8) | 0x00); + let label = t!("terminal.close_pane").to_string(); + div() + .id(btn_id.clone()) + .occlude() + .absolute() + .top_1() + .left_1() + .flex() + .items_center() + .justify_center() + .size(px(20.0)) + .rounded(RADIUS_SM) + .bg(rest_bg) + .with_transition(btn_id) + .on_hover(move |hovered, w, cx| { + if *hovered { + tooltip_ctrl.update(cx, |t, cx| { + t.show(label.clone(), w.mouse_position(), cx); + }); + } else { + tooltip_ctrl.update(cx, |t, cx| { + t.hide(cx); + }); + } + }) + .on_click(move |_e, _w, cx| { + handle.update(cx, |app, cx| { + app.close_pane(tab_id, pane_id, cx); + }); + cx.stop_propagation(); + }) + .transition_on_hover(duration_fast(), EASE_STANDARD, move |hovered, el| { + if *hovered { + el.bg(hover_bg) + } else { + el.bg(rgba((surface_hover() << 8) | 0x00)) + } + }) + .child( + svg() + .path("icons/x.svg") + .size(px(10.0)) + .text_color(rgb(text_muted())), + ) +} + /// The pane id of the first leaf under a node (used to key dividers). fn leaf_pane_id(node: &SplitNode) -> u64 { match node { From f1ce8d76c369e95442ea44bd80073be1459a6dca Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 14:36:13 +0800 Subject: [PATCH 6/9] feat(terminal): focus ring on the active split pane (#89) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop the in-pane close button (it felt out of place) and answer the actual question instead: which of these identical panes am I typing into? The old active-pane tint never showed — it sat on the pane container and TerminalView paints an opaque term_bg over it, so there was no visible difference between panes at all. The ring is painted after the view, as an inset_0 overlay with no listeners, so it draws above the terminal and clicks/drags still pass through to it. The border uses input_border_focused() — the same color the UI already gives a focused input — and only appears when the tab is split; a single pane fills the window and needs no ring. Crossfades via the transition registry when focus moves between panes. --- crabport-ui/src/layouts/content.rs | 138 +++++++---------------------- 1 file changed, 34 insertions(+), 104 deletions(-) diff --git a/crabport-ui/src/layouts/content.rs b/crabport-ui/src/layouts/content.rs index d07286f..dd3bfcc 100644 --- a/crabport-ui/src/layouts/content.rs +++ b/crabport-ui/src/layouts/content.rs @@ -273,7 +273,6 @@ pub fn render_content( tab_id, pane_views, handle, - ctx.tooltip.clone(), ) .into_any_element() } else if let Some(terminal_entity) = terminal_views.get(&tab_id) { @@ -1052,7 +1051,6 @@ fn render_split_node( tab_id: u64, pane_views: &HashMap>, handle: &Entity, - tooltip_ctrl: Entity, ) -> AnyElement { use gpui_component::resizable::{h_resizable, resizable_panel, v_resizable}; match node { @@ -1063,7 +1061,6 @@ fn render_split_node( tab_id, pane_views, handle, - tooltip_ctrl, ) .into_any_element(), SplitNode::Split { dir, a, b, .. } => { @@ -1076,24 +1073,10 @@ fn render_split_node( }; // Render children. For a nested split child, wrap it in a // `resizable_panel` so the inner group fills its allocated space. - let child_a = render_split_child( - a, - active_pane, - multi_pane, - tab_id, - pane_views, - handle, - tooltip_ctrl.clone(), - ); - let child_b = render_split_child( - b, - active_pane, - multi_pane, - tab_id, - pane_views, - handle, - tooltip_ctrl, - ); + let child_a = + render_split_child(a, active_pane, multi_pane, tab_id, pane_views, handle); + let child_b = + render_split_child(b, active_pane, multi_pane, tab_id, pane_views, handle); let group = if axis == gpui::Axis::Horizontal { h_resizable(group_id) @@ -1117,7 +1100,6 @@ fn render_split_child( tab_id: u64, pane_views: &HashMap>, handle: &Entity, - tooltip_ctrl: Entity, ) -> AnyElement { match node { SplitNode::Pane(pane_id) => render_pane( @@ -1127,27 +1109,19 @@ fn render_split_child( tab_id, pane_views, handle, - tooltip_ctrl, ) .into_any_element(), SplitNode::Split { .. } => { // Nested split: render as a group, which itself becomes the child. - render_split_node( - node, - active_pane, - multi_pane, - tab_id, - pane_views, - handle, - tooltip_ctrl, - ) + render_split_node(node, active_pane, multi_pane, tab_id, pane_views, handle) } } } -/// Render a single terminal pane with click-to-focus + active highlight, -/// and — when the tab holds more than one pane — its own close button -/// (#89): every split pane closes itself, like a little window. +/// Render a single terminal pane with click-to-focus, and — when the tab +/// holds more than one pane — a focus ring on the pane that owns the +/// keyboard (#89): with identical-looking panes, the ring is what tells you +/// at a glance which terminal you're typing into. fn render_pane( pane_id: u64, active_pane: u64, @@ -1155,16 +1129,15 @@ fn render_pane( tab_id: u64, pane_views: &HashMap>, handle: &Entity, - tooltip_ctrl: Entity, ) -> impl IntoElement { let is_active = pane_id == active_pane; let view = pane_views.get(&pane_id).cloned(); let view_for_focus = view.clone(); + let ring_id = ElementId::Name(format!("pane-focus-{}-{}", tab_id, pane_id).into()); let mut el = div() .id(ElementId::Name( format!("pane-{}-{}", tab_id, pane_id).into(), )) - .relative() .size_full() // Occlude so this pane's hitbox blocks sibling panes' mouse // handlers — without this, overlapping hitboxes (e.g. when the @@ -1172,7 +1145,6 @@ fn render_pane( // single click to fire `on_mouse_down` on *every* pane, re-focusing // the wrong one. .occlude() - .when(is_active, |el| el.bg(rgba((surface_hover() << 8) | 0x18))) .on_mouse_down(MouseButton::Left, { let handle = handle.clone(); move |_e, w, cx| { @@ -1189,77 +1161,35 @@ fn render_pane( if let Some(view) = view { el = el.child(view); } + // The focus ring paints *after* the view, because TerminalView fills + // itself with an opaque `term_bg` — the old active-pane tint sat on this + // container and was painted over, which is why the focused pane was + // impossible to pick out. A plain bordered overlay has no listeners, so + // clicks and drags pass through to the terminal beneath; the ring fades + // in on the pane that takes focus and out of the one that loses it. if multi_pane { - el = el.child(render_pane_close_button( - pane_id, - tab_id, - handle.clone(), - tooltip_ctrl, - )); + el = el.child( + div() + .id(ring_id.clone()) + .absolute() + .inset_0() + // Pointer-events: none — the overlay is purely visual. + .bg(rgba(0x00000000)) + .border_1() + .border_color(rgb(input_border_focused())) + .with_transition(ring_id) + .transition_when_else( + is_active, + duration_fast(), + EASE_STANDARD, + |el| el.opacity(1.0), + |el| el.opacity(0.0), + ), + ); } el } -/// The per-pane close button (#89). Sits at the pane's top-left: the -/// top-right corner is occupied by the global split/panel cluster (and the -/// search bar that slides beneath it), so a top-left control reads like a -/// little window's traffic light and never collides with it. `.occlude()` -/// keeps the press from starting a selection in the terminal below. -fn render_pane_close_button( - pane_id: u64, - tab_id: u64, - handle: Entity, - tooltip_ctrl: Entity, -) -> impl IntoElement { - let btn_id = ElementId::Name(format!("pane-close-{}-{}", tab_id, pane_id).into()); - let hover_bg = rgba((surface_hover() << 8) | 0xFF); - let rest_bg = rgba((surface_hover() << 8) | 0x00); - let label = t!("terminal.close_pane").to_string(); - div() - .id(btn_id.clone()) - .occlude() - .absolute() - .top_1() - .left_1() - .flex() - .items_center() - .justify_center() - .size(px(20.0)) - .rounded(RADIUS_SM) - .bg(rest_bg) - .with_transition(btn_id) - .on_hover(move |hovered, w, cx| { - if *hovered { - tooltip_ctrl.update(cx, |t, cx| { - t.show(label.clone(), w.mouse_position(), cx); - }); - } else { - tooltip_ctrl.update(cx, |t, cx| { - t.hide(cx); - }); - } - }) - .on_click(move |_e, _w, cx| { - handle.update(cx, |app, cx| { - app.close_pane(tab_id, pane_id, cx); - }); - cx.stop_propagation(); - }) - .transition_on_hover(duration_fast(), EASE_STANDARD, move |hovered, el| { - if *hovered { - el.bg(hover_bg) - } else { - el.bg(rgba((surface_hover() << 8) | 0x00)) - } - }) - .child( - svg() - .path("icons/x.svg") - .size(px(10.0)) - .text_color(rgb(text_muted())), - ) -} - /// The pane id of the first leaf under a node (used to key dividers). fn leaf_pane_id(node: &SplitNode) -> u64 { match node { From 791d116651d95460ed34dd094c63ec0204e1f70d Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 14:59:56 +0800 Subject: [PATCH 7/9] feat(terminal): edge glow on the focused split pane (#89) Swap the flat 1px focus ring for a light wash that starts at every edge and fades toward the centre of the pane, which reads as the pane lighting up rather than being outlined. gpui 0.2 has two-stop linear gradients only, so the wash is composed from one strip per side (64pt deep, lit at the edge, transparent at 1.0); neighbouring strips overlap at the corners, pooling the light there the way a rounded glow does. Both stops share the focus hue so the fade never drifts gray through Hsla interpolation. The overlay still has no listeners, so clicks and drags reach the terminal beneath, and the whole thing crossfades when focus moves between panes. --- crabport-ui/src/layouts/content.rs | 72 +++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/crabport-ui/src/layouts/content.rs b/crabport-ui/src/layouts/content.rs index dd3bfcc..5447350 100644 --- a/crabport-ui/src/layouts/content.rs +++ b/crabport-ui/src/layouts/content.rs @@ -1133,7 +1133,7 @@ fn render_pane( let is_active = pane_id == active_pane; let view = pane_views.get(&pane_id).cloned(); let view_for_focus = view.clone(); - let ring_id = ElementId::Name(format!("pane-focus-{}-{}", tab_id, pane_id).into()); + let glow_id = ElementId::Name(format!("pane-glow-{}-{}", tab_id, pane_id).into()); let mut el = div() .id(ElementId::Name( format!("pane-{}-{}", tab_id, pane_id).into(), @@ -1161,29 +1161,77 @@ fn render_pane( if let Some(view) = view { el = el.child(view); } - // The focus ring paints *after* the view, because TerminalView fills - // itself with an opaque `term_bg` — the old active-pane tint sat on this + // The glow paints *after* the view, because TerminalView fills itself + // with an opaque `term_bg` — the old active-pane tint sat on this // container and was painted over, which is why the focused pane was - // impossible to pick out. A plain bordered overlay has no listeners, so - // clicks and drags pass through to the terminal beneath; the ring fades - // in on the pane that takes focus and out of the one that loses it. + // impossible to pick out. The overlay has no listeners, so every click + // and drag passes through to the terminal beneath; the glow fades in on + // the pane that takes focus and out of the one that loses it. if multi_pane { + let glow = input_border_focused(); + // Same hue at both stops so the fade never drifts gray in Hsla. + let lit = rgba((glow << 8) | 0x38); + let clear = rgba((glow << 8) | 0x00); + let glow_px = px(64.0); + // gpui 0.2 has two-stop linear gradients only, so the radial + // edge-to-centre wash is composed from one strip per side; the two + // neighbours overlap at each corner, pooling the light there. + let strip = |angle: f32| { + linear_gradient( + angle, + linear_color_stop(lit, 0.0), + linear_color_stop(clear, 1.0), + ) + }; el = el.child( div() - .id(ring_id.clone()) + .id(glow_id.clone()) .absolute() .inset_0() - // Pointer-events: none — the overlay is purely visual. - .bg(rgba(0x00000000)) - .border_1() - .border_color(rgb(input_border_focused())) - .with_transition(ring_id) + // Pointer-events: none — the glow is purely visual. + .with_transition(glow_id) .transition_when_else( is_active, duration_fast(), EASE_STANDARD, |el| el.opacity(1.0), |el| el.opacity(0.0), + ) + .child( + div() + .absolute() + .top_0() + .left_0() + .w_full() + .h(glow_px) + .bg(strip(180.0)), + ) + .child( + div() + .absolute() + .bottom_0() + .left_0() + .w_full() + .h(glow_px) + .bg(strip(0.0)), + ) + .child( + div() + .absolute() + .top_0() + .left_0() + .h_full() + .w(glow_px) + .bg(strip(90.0)), + ) + .child( + div() + .absolute() + .top_0() + .right_0() + .h_full() + .w(glow_px) + .bg(strip(270.0)), ), ); } From 209eb99a09a5f62dbebbc01ea56539a1e746b63d Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 15:26:17 +0800 Subject: [PATCH 8/9] style(terminal): tighten the pane focus glow to a 24pt rim 64pt reached too far into the pane; the wash now hugs the edge and leaves the middle of the terminal plain. --- crabport-ui/src/layouts/content.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crabport-ui/src/layouts/content.rs b/crabport-ui/src/layouts/content.rs index 5447350..42ae2bf 100644 --- a/crabport-ui/src/layouts/content.rs +++ b/crabport-ui/src/layouts/content.rs @@ -1172,7 +1172,9 @@ fn render_pane( // Same hue at both stops so the fade never drifts gray in Hsla. let lit = rgba((glow << 8) | 0x38); let clear = rgba((glow << 8) | 0x00); - let glow_px = px(64.0); + // A tight rim: the wash reaches only ~24pt in from each edge, so + // the terminal keeps its plain background across the middle. + let glow_px = px(24.0); // gpui 0.2 has two-stop linear gradients only, so the radial // edge-to-centre wash is composed from one strip per side; the two // neighbours overlap at each corner, pooling the light there. From e84915536a3a56f8e38218d3b619b062c8d2e39b Mon Sep 17 00:00:00 2001 From: ch1ll321 Date: Thu, 12 Nov 2026 15:40:25 +0800 Subject: [PATCH 9/9] style(terminal): pane focus glow down to 12pt A hairline rim of light on the focused split pane; anything wider read as a wash over the terminal. --- crabport-ui/src/layouts/content.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crabport-ui/src/layouts/content.rs b/crabport-ui/src/layouts/content.rs index 42ae2bf..246ff5a 100644 --- a/crabport-ui/src/layouts/content.rs +++ b/crabport-ui/src/layouts/content.rs @@ -1172,9 +1172,9 @@ fn render_pane( // Same hue at both stops so the fade never drifts gray in Hsla. let lit = rgba((glow << 8) | 0x38); let clear = rgba((glow << 8) | 0x00); - // A tight rim: the wash reaches only ~24pt in from each edge, so + // A tight rim: the wash reaches only ~12pt in from each edge, so // the terminal keeps its plain background across the middle. - let glow_px = px(24.0); + let glow_px = px(12.0); // gpui 0.2 has two-stop linear gradients only, so the radial // edge-to-centre wash is composed from one strip per side; the two // neighbours overlap at each corner, pooling the light there.