Skip to content

armgit / herdr

Public Imported from GitHub
0

the runtime your coding agents live on

fix: open goto search on shifted slash in report-all panes (#5090)

Can Celik2563803dca97
diff --git a/src/client/shell/overlay_input.rs b/src/client/shell/overlay_input.rs
index 653826a64..5ab6e6593 100644
--- a/src/client/shell/overlay_input.rs
+++ b/src/client/shell/overlay_input.rs
@@ -718,7 +718,14 @@ impl ClientShellState {
outcome.repaint = true;
return;
}
- if code == KeyCode::Char('/') && modifiers.is_empty() {
+ // Match the typed character so layouts where `/` needs Shift work
+ // when the host reports it as a shifted key (report-all panes).
+ // A shifted key needs the host's text or shifted alternate: bare
+ // `CSI 47;2u` is Shift+/, which is not `/` on most layouts.
+ let shifted_without_evidence = key.modifiers.contains(KeyModifiers::SHIFT)
+ && key.generated_text.is_none()
+ && key.shifted_codepoint.is_none();
+ if !shifted_without_evidence && crate::input::keybind_help_text_char(key) == Some('/') {
if let Some(ClientShellOverlay::Navigator(navigator)) = self.overlay.as_mut() {
navigator.search_focused = true;
navigator.filter = None;
diff --git a/src/client/shell/tests/input_conformance.rs b/src/client/shell/tests/input_conformance.rs
index 4854974c4..5053a616f 100644
--- a/src/client/shell/tests/input_conformance.rs
+++ b/src/client/shell/tests/input_conformance.rs
@@ -1691,6 +1691,61 @@ async fn overlapping_layout_and_us_keys_release_exactly() {
}
}
+#[cfg(unix)]
+#[tokio::test(flavor = "multi_thread")]
+async fn goto_search_opens_on_shifted_slash_from_a_report_all_pane() {
+ // #4963, recorded from Ghostty 1.3.1 with a Portuguese layout, where `/` is
+ // Shift+7. With a plain pane Herdr keeps the host at flags 7 and the press
+ // arrives as text; when the focused pane asks for all keys Herdr pushes 31
+ // and the press arrives as a report carrying the shifted key and its text.
+ for (pane_mode, press, release) in [
+ (&b""[..], &b"/"[..], &b"\x1b[55:47;2:3u"[..]),
+ (b"\x1b[>31u", b"\x1b[55:47;2;47u", b"\x1b[55:47;2:3u"),
+ ] {
+ let mut herdr = HerdrPath::new(HostProfile::Kitty, pane_mode);
+ herdr.state.open_navigator_overlay();
+ assert_eq!(herdr.feed(press), None, "{}", show(pane_mode));
+ assert_eq!(herdr.feed(release), None, "{}", show(pane_mode));
+ assert!(
+ matches!(
+ &herdr.state.overlay,
+ Some(ClientShellOverlay::Navigator(navigator)) if navigator.search_focused
+ ),
+ "goto search did not activate for pane {}",
+ show(pane_mode)
+ );
+ }
+}
+
+#[cfg(unix)]
+#[tokio::test(flavor = "multi_thread")]
+async fn goto_search_opens_only_for_a_typed_slash() {
+ // (pane mode, host bytes, whether goto search opens)
+ for (pane_mode, press, opens) in [
+ // Unshifted `/` reported as a kitty key.
+ (&b"\x1b[>31u"[..], &b"\x1b[47u"[..], true),
+ // Shift+/ typing `?` without a shifted alternate is not `/`.
+ (b"\x1b[>31u", b"\x1b[47;2;63u", false),
+ // Shift+/ without text or alternate says nothing about `/`.
+ (b"\x1b[>31u", b"\x1b[47;2u", false),
+ // Shift+7 with a `/` alternate and no text is `/`.
+ (b"\x1b[>31u", b"\x1b[55:47;2u", true),
+ // Ctrl+/ and Alt+/ are not text.
+ (b"\x1b[>31u", b"\x1b[47;5u", false),
+ (b"\x1b[>31u", b"\x1b[47;3u", false),
+ (b"", b"\x1b/", false),
+ ] {
+ let mut herdr = HerdrPath::new(HostProfile::Kitty, pane_mode);
+ herdr.state.open_navigator_overlay();
+ let _ = herdr.feed(press);
+ let focused = matches!(
+ &herdr.state.overlay,
+ Some(ClientShellOverlay::Navigator(navigator)) if navigator.search_focused
+ );
+ assert_eq!(focused, opens, "{}", show(press));
+ }
+}
+
#[cfg(unix)]
#[tokio::test(flavor = "multi_thread")]
async fn wezterm_escape_tap_reaches_the_pane_with_doubled_escape_preserved() {
diff --git a/src/input/keybind_help.rs b/src/input/keybind_help.rs
index cb1fdb99d..800794888 100644
--- a/src/input/keybind_help.rs
+++ b/src/input/keybind_help.rs
@@ -10,10 +10,21 @@ use crate::{
pub(crate) type KeybindHelpEntry = (String, Cow<'static, str>);
pub(crate) type KeybindHelpGroup = (&'static str, Vec<KeybindHelpEntry>);
+/// The character a key types, for overlay shortcuts and text fields.
pub(crate) fn keybind_help_text_char(key: &TerminalKey) -> Option<char> {
if !key.modifiers.difference(KeyModifiers::SHIFT).is_empty() {
return None;
}
+ // Text the host says the key produced is authoritative: kitty hosts may
+ // report Shift+/ as `/` with text `?` and no shifted alternate.
+ if let Some(text) = key.generated_text.as_deref() {
+ let mut chars = text.chars();
+ if let (Some(character), None) = (chars.next(), chars.next()) {
+ if !character.is_control() {
+ return Some(character);
+ }
+ }
+ }
if let Some(character) = key.shifted_codepoint.and_then(char::from_u32) {
return Some(character);
}
@@ -256,6 +267,28 @@ mod tests {
]
}
+ #[test]
+ fn text_char_prefers_generated_text_then_alternate_then_code() {
+ let parse = |bytes: &str| {
+ crate::input::parse_terminal_key_sequence(bytes)
+ .unwrap_or_else(|| panic!("{bytes:?} parses"))
+ };
+ for (bytes, want) in [
+ // Shift+/ typing `?` with no shifted alternate.
+ ("\x1b[47;2;63u", Some('?')),
+ ("\x1b[47u", Some('/')),
+ ("/", Some('/')),
+ // Portuguese Shift+7: alternate and text agree.
+ ("\x1b[55:47;2;47u", Some('/')),
+ ("\x1b[55:47;2u", Some('/')),
+ ("\x1b[55;2u", Some('7')),
+ ("\x1b[47;5u", None),
+ ("\x1b[47;3u", None),
+ ] {
+ assert_eq!(keybind_help_text_char(&parse(bytes)), want, "{bytes:?}");
+ }
+ }
+
#[test]
fn filter_matches_labels_and_shortcuts_case_insensitively() {
let filtered = filter_keybind_help_groups(groups(), "WoRk");