feat: support macOS modified backspace deletion
This commit is contained in:
+61
@@ -882,6 +882,14 @@ fn typing_ready(
|
||||
}
|
||||
|
||||
fn translate(key: KeyEvent) -> Option<Input> {
|
||||
#[cfg(target_os = "macos")]
|
||||
if key.code == KeyCode::Backspace {
|
||||
match key.modifiers {
|
||||
KeyModifiers::ALT => return Some(Input::AltBackspace),
|
||||
KeyModifiers::SUPER => return Some(Input::SuperBackspace),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if key
|
||||
.modifiers
|
||||
.intersects(KeyModifiers::SUPER | KeyModifiers::HYPER | KeyModifiers::META)
|
||||
@@ -10025,6 +10033,59 @@ end
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn macos_modified_backspace_edits_words_and_line_prefix_from_terminal_events() {
|
||||
let directory = Directory::new();
|
||||
let path = directory.file("input.txt", "before\nalpha βeta SUFFIX\nlast");
|
||||
let mut session = EditorSession::open(Some(path), vec![], None).unwrap();
|
||||
session.handle(Input::Down);
|
||||
session.handle(Input::Home);
|
||||
session.handle(Input::Char('i'));
|
||||
for _ in 0..13 {
|
||||
session.handle(Input::Right);
|
||||
}
|
||||
session.handle(translate(KeyEvent::new(KeyCode::Backspace, KeyModifiers::ALT)).unwrap());
|
||||
assert_eq!(session.editor().lines(), ["before", "alpha SUFFIX", "last"]);
|
||||
session.handle(translate(KeyEvent::new(KeyCode::Backspace, KeyModifiers::SUPER)).unwrap());
|
||||
assert_eq!(session.editor().lines(), ["before", "SUFFIX", "last"]);
|
||||
|
||||
for modifiers in [
|
||||
KeyModifiers::META,
|
||||
KeyModifiers::HYPER,
|
||||
KeyModifiers::ALT | KeyModifiers::CONTROL,
|
||||
KeyModifiers::ALT | KeyModifiers::SHIFT,
|
||||
KeyModifiers::SUPER | KeyModifiers::CONTROL,
|
||||
KeyModifiers::SUPER | KeyModifiers::SHIFT,
|
||||
KeyModifiers::SUPER | KeyModifiers::ALT,
|
||||
KeyModifiers::SUPER | KeyModifiers::META,
|
||||
] {
|
||||
assert_eq!(
|
||||
translate(KeyEvent::new(KeyCode::Backspace, modifiers)),
|
||||
None
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
translate(KeyEvent::new(KeyCode::Char('a'), KeyModifiers::SUPER)),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
#[test]
|
||||
fn modified_backspace_keeps_non_macos_terminal_defaults() {
|
||||
for modifiers in [KeyModifiers::ALT, KeyModifiers::SUPER] {
|
||||
assert_eq!(
|
||||
translate(KeyEvent::new(KeyCode::Backspace, modifiers)),
|
||||
None
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
translate(KeyEvent::new(KeyCode::Backspace, KeyModifiers::CONTROL)),
|
||||
Some(Input::Backspace)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wheel_routes_to_floating_and_unfocused_docked_files_without_changing_selection() {
|
||||
let directory = Directory::new();
|
||||
|
||||
Reference in New Issue
Block a user