mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-09-21 16:02:20 +00:00
fix(terminal): accept ASCII keystrokes in the Ctrl+R reverse-search prompt
The reverse-search query only took text from the IME commit path (input_text -> push_query), so a CJK input source could type into it but a plain ASCII source — and Linux, where prefers_ime_for_printable_keys is false — delivered printable keys via on_key_down, where handle_key ignored them. Ctrl+R opened, but the search box swallowed every keystroke. Forward printable key_char events from handle_reverse_search_key into push_query, mirroring the editor's existing key_char path; control/Cmd/Alt chords and non-printable keys still fall through to the control-key handling. Fixes ASCII typing on macOS and all typing on Linux. Reported on V2EX. Claude-Session: https://claude.ai/code/session_01ABey161AUxhgmJC3PRoYtF
This commit is contained in:
@@ -65,7 +65,10 @@ impl ReverseSearch {
|
||||
}
|
||||
}
|
||||
|
||||
/// Append typed text (arriving via the IME path) to the query and re-search.
|
||||
/// Append typed text to the query and re-search. Text arrives either via the
|
||||
/// IME path (`replace_text_in_range` → the view's `input_text`) or, for a plain
|
||||
/// ASCII input source, as a direct `key_char` the view forwards from
|
||||
/// `handle_reverse_search_key`.
|
||||
pub(super) fn push_query(&mut self, text: &str, history: &[String]) {
|
||||
self.query.push_str(text);
|
||||
self.update(history, false);
|
||||
|
||||
@@ -1980,6 +1980,26 @@ impl TerminalView {
|
||||
/// query/match logic (`reverse_search` module); the view just applies the
|
||||
/// resulting [`reverse_search::Action`] and repaints.
|
||||
fn handle_reverse_search_key(&mut self, ks: &gpui::Keystroke, cx: &mut Context<Self>) {
|
||||
// Printable text typed into the query. A CJK input source routes it through
|
||||
// the IME (`input_text` → `push_query`), but a plain ASCII input source —
|
||||
// and Linux, where `prefers_ime_for_printable_keys` is false — delivers it
|
||||
// here as an ordinary key event carrying `key_char`. Without this the search
|
||||
// field can only be typed into via an IME: Ctrl+R opens, but ASCII
|
||||
// keystrokes vanish. Mirror the editor's `key_char` path (`handle_editor_key`);
|
||||
// control / Cmd / Alt chords and non-printable keys (Enter/Backspace/Esc have
|
||||
// no printable `key_char`) fall through to the control-key handling below.
|
||||
let m = &ks.modifiers;
|
||||
if !m.control && !m.platform && !m.alt {
|
||||
if let Some(ch) = ks.key_char.as_deref() {
|
||||
if !ch.is_empty() && ch.chars().all(|c| c >= '\u{20}' && c != '\u{7f}') {
|
||||
if let Some(rs) = self.reverse_search.as_mut() {
|
||||
rs.push_query(ch, &self.history);
|
||||
}
|
||||
cx.notify();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(rs) = self.reverse_search.as_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user