Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions native/gpui/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,9 @@ pub fn bindings() -> Vec<KeyBinding> { bindings_for(crate::keys::mac()) }
pub fn bindings_for(mac: bool) -> Vec<KeyBinding> {
let mut v = vec![
KeyBinding::new("backspace", Backspace, Some("TextInput")),
KeyBinding::new("shift-backspace", Backspace, Some("TextInput")),
KeyBinding::new("delete", Delete, Some("TextInput")),
KeyBinding::new("shift-delete", Delete, Some("TextInput")),
KeyBinding::new("left", Left, Some("TextInput")),
KeyBinding::new("right", Right, Some("TextInput")),
KeyBinding::new("shift-left", SelectLeft, Some("TextInput")),
Expand Down
9 changes: 6 additions & 3 deletions native/gpui/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,11 @@ mod tests {
assert_eq!(d("shift-enter", &["Composer"]), "composer::Newline");
assert_eq!(d("/", &["Composer"]), "", "a slash is typed"); assert_eq!(d("b", &["Composer"]), "");
// no shortcut shadows an editing key of the composer
for k in ["ctrl-a", "ctrl-c", "ctrl-x", "ctrl-v", "ctrl-z", "ctrl-y", "ctrl-shift-z", "ctrl-left", "ctrl-right", "ctrl-backspace", "ctrl-home", "ctrl-end", "home", "end", "tab", "backspace", "delete"] {
for k in ["ctrl-a", "ctrl-c", "ctrl-x", "ctrl-v", "ctrl-z", "ctrl-y", "ctrl-shift-z", "ctrl-left", "ctrl-right", "ctrl-backspace", "ctrl-home", "ctrl-end", "home", "end", "tab", "backspace", "shift-backspace", "delete", "shift-delete"] {
let a = d(k, &["Composer"]); assert!(a.starts_with("composer::"), "{k} must stay the composer's, got {a}");
}
assert_eq!(d("shift-backspace", &["Composer"]), "composer::Backspace");
assert_eq!(d("shift-delete", &["Composer"]), "composer::Delete");
assert_eq!(d("shift-tab", &["Composer"]), "keys::TogglePlanMode");
assert_eq!(d("shift-tab", &["Picker", "Composer"]), "keys::PickBackTab");
assert_eq!(d("alt-shift-p", &[]), "keys::MgmtPlan");
Expand All @@ -637,7 +639,8 @@ mod tests {
assert_eq!(d("ctrl-z", &["DrawPad"]), "pad::Undo"); assert_eq!(d("delete", &["DrawPad"]), "pad::Delete"); assert_eq!(d("backspace", &["DrawPad"]), "pad::Delete");
assert_eq!(d("ctrl-z", &["Composer"]), "composer::Undo", "the message box keeps its own undo");
assert_eq!(d("ctrl-z", &["DrawPad", "PadLength"]), "composer::Undo", "in the length box it undoes the typing");
assert_eq!(d("delete", &["DrawPad", "PadLength"]), "composer::Delete"); assert_eq!(d("enter", &["DrawPad", "PadLength"]), "composer::Go");
assert_eq!(d("delete", &["DrawPad", "PadLength"]), "composer::Delete"); assert_eq!(d("shift-delete", &["DrawPad", "PadLength"]), "composer::Delete");
assert_eq!(d("shift-backspace", &["DrawPad", "PadLength"]), "composer::Backspace"); assert_eq!(d("enter", &["DrawPad", "PadLength"]), "composer::Go");
assert_eq!(d("escape", &["DrawPad"]), "backplane::ClosePopup"); assert_eq!(d("escape", &["DrawPad", "PadLength"]), "backplane::ClosePopup");
}
#[test] fn nothing_behind_the_pad_moves_while_it_is_open() {
Expand Down Expand Up @@ -680,7 +683,7 @@ mod tests {
if mac() { assert_eq!(d("cmd-c", &["Terminal"]), "term::Copy"); assert_eq!(d("cmd-v", &["Terminal"]), "term::Paste"); }
}
#[test] fn every_other_shortcut_is_the_shells_inside_the_terminal() {
for k in ["ctrl-c", "ctrl-k", "ctrl-n", "ctrl-b", "ctrl-d", "ctrl-p", "ctrl-.", "ctrl-m", "ctrl-h", "ctrl-shift-p", "ctrl-shift-f", "ctrl-shift-s", "ctrl-shift-u", "ctrl-shift-[", "alt-1", "ctrl-1", "ctrl-z", "ctrl-a", "enter", "tab", "backspace", "delete", "/", "b", "s", "3", "w", "`"] {
for k in ["ctrl-c", "ctrl-k", "ctrl-n", "ctrl-b", "ctrl-d", "ctrl-p", "ctrl-.", "ctrl-m", "ctrl-h", "ctrl-shift-p", "ctrl-shift-f", "ctrl-shift-s", "ctrl-shift-u", "ctrl-shift-[", "alt-1", "ctrl-1", "ctrl-z", "ctrl-a", "enter", "tab", "backspace", "shift-backspace", "delete", "shift-delete", "/", "b", "s", "3", "w", "`"] {
if mac() && k == "ctrl-c" { continue } // Cmd+C copies in the terminal on a Mac (the secondary chord is its own)
assert_eq!(d(k, &["Terminal"]), "", "{k} must reach the shell");
}
Expand Down
25 changes: 24 additions & 1 deletion native/gpui/src/screens/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ pub fn bindings_for(mac: bool) -> Vec<KeyBinding> {
/* i18n-ok: key contexts */ for ctx in ["Composer", "AskInput", "ImpInput", "PickInput", "FindInput", "PadLength"] {
let c = Some(ctx);
v.extend([
KeyBinding::new("backspace", Backspace, c), KeyBinding::new("delete", Delete, c),
KeyBinding::new("backspace", Backspace, c), KeyBinding::new("shift-backspace", Backspace, c),
KeyBinding::new("delete", Delete, c), KeyBinding::new("shift-delete", Delete, c),
KeyBinding::new("left", Left, c), KeyBinding::new("right", Right, c),
KeyBinding::new("shift-left", SelLeft, c), KeyBinding::new("shift-right", SelRight, c),
KeyBinding::new("tab", Tab, c), KeyBinding::new("up", Up, c), KeyBinding::new("down", Down, c), KeyBinding::new("shift-up", SelUp, c), KeyBinding::new("shift-down", SelDown, c),
Expand Down Expand Up @@ -502,6 +503,28 @@ mod tests {
for (key, a) in [("cmd-left", "Home"), ("cmd-right", "End"), ("cmd-v", "Paste"), ("cmd-c", "Copy"), ("cmd-x", "Cut"), ("cmd-a", "SelectAll"), ("ctrl-v", "Paste")] { assert_eq!(k(true, key), format!("text_input::{a}"), "{key}"); }
assert_eq!(k(false, "cmd-left"), ""); assert_eq!(k(false, "ctrl-v"), "text_input::Paste");
}
#[test] fn shift_backspace_and_shift_delete_delete_characters() {
for mac in [false, true] {
for ctx in ["Composer", "AskInput", "ImpInput", "PickInput", "FindInput", "PadLength"] {
assert_eq!(edit_key(mac, "shift-backspace", ctx), "composer::Backspace", "{ctx} mac={mac}");
assert_eq!(edit_key(mac, "shift-delete", ctx), "composer::Delete", "{ctx} mac={mac}");
}
let map = gpui::Keymap::new(crate::input::bindings_for(mac));
let ti = [gpui::KeyContext::parse("TextInput").unwrap()];
let resolve = |key: &str| map.bindings_for_input(&[gpui::Keystroke::parse(key).unwrap()], &ti).0.first().map(|b| b.action().name().to_string()).unwrap_or_default();
assert_eq!(resolve("shift-backspace"), "text_input::Backspace", "TextInput mac={mac}");
assert_eq!(resolve("shift-delete"), "text_input::Delete", "TextInput mac={mac}");
}
let mut ed = Editor::default();
ed.insert("abc");
assert_eq!(edit_key(false, "shift-backspace", "Composer"), "composer::Backspace");
ed.backspace(false);
assert_eq!(ed.text(), "ab");
ed.place(0, false);
assert_eq!(edit_key(false, "shift-delete", "Composer"), "composer::Delete");
ed.delete(false);
assert_eq!(ed.text(), "b");
}
#[test] fn the_mask_keeps_every_byte_offset_and_newline() {
let s = "key-é日\nline2";
let m = mask(s);
Expand Down
2 changes: 1 addition & 1 deletion native/gpui/src/screens/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ mod tests {
assert_eq!(b(&typed("a", "a")), b"a"); assert_eq!(b(&typed("shift-a", "A")), b"A"); assert_eq!(b(&typed("`", "`")), b"`", "a backtick is the shell's");
assert_eq!(b(&typed("space", " ")), b" "); assert_eq!(b(&ks("ctrl-space")), [0]);
assert_eq!(b(&ks("ctrl-c")), [3]); assert_eq!(b(&ks("ctrl-d")), [4]); assert_eq!(b(&ks("ctrl-k")), [11]); assert_eq!(b(&ks("ctrl-l")), [12]);
assert_eq!(b(&ks("enter")), [13]); assert_eq!(b(&ks("backspace")), [127]); assert_eq!(b(&ks("tab")), [9]); assert_eq!(b(&ks("shift-tab")), b"\x1b[Z");
assert_eq!(b(&ks("enter")), [13]); assert_eq!(b(&ks("backspace")), [127]); assert_eq!(b(&ks("shift-backspace")), [127]); assert_eq!(b(&ks("tab")), [9]); assert_eq!(b(&ks("shift-tab")), b"\x1b[Z");
assert_eq!(b(&ks("escape")), [27]); assert_eq!(b(&ks("up")), b"\x1b[A"); assert_eq!(b(&ks("left")), b"\x1b[D"); assert_eq!(b(&ks("ctrl-right")), b"\x1b[1;5C");
assert_eq!(b(&ks("home")), b"\x1b[H"); assert_eq!(b(&ks("delete")), b"\x1b[3~"); assert_eq!(b(&ks("pageup")), b"\x1b[5~"); assert_eq!(b(&ks("f1")), b"\x1bOP"); assert_eq!(b(&ks("f5")), b"\x1b[15~");
assert_eq!(b(&typed("é", "é")), "é".as_bytes());
Expand Down
Loading