fix(tui/composer): restore Option+Enter newline and Cmd+Z undo

This commit is contained in:
James Peter
2025-09-27 06:22:09 +10:00
parent d1eeb0fd64
commit eed19520e7
+22
View File
@@ -242,6 +242,10 @@ impl TextArea {
KeyEvent { code: KeyCode::Char('\u{0006}'), modifiers: KeyModifiers::NONE, .. } /* ^F */ => {
self.move_cursor_right();
}
KeyEvent {
code: KeyCode::Char(c),
..
} if matches!(c, '\n' | '\r') => self.insert_str("\n"),
KeyEvent {
code: KeyCode::Char(c),
// Insert plain characters (and Shift-modified). Do NOT insert when ALT is held,
@@ -321,6 +325,13 @@ impl TextArea {
} => {
self.undo();
}
KeyEvent {
code: KeyCode::Char('z'),
modifiers: KeyModifiers::SUPER,
..
} => {
self.undo();
}
// macOS-like shortcuts (when terminals report the Command key as SUPER):
// Cmd+Left -> move to beginning of line
// Cmd+Right -> move to end of line
@@ -1275,6 +1286,17 @@ mod tests {
assert_eq!(t.cursor(), 0);
}
#[test]
fn alt_enter_inserts_newline() {
let mut t = TextArea::new();
t.input(KeyEvent::new(KeyCode::Enter, KeyModifiers::ALT));
assert_eq!(t.text(), "\n");
let mut t = TextArea::new();
t.input(KeyEvent::new(KeyCode::Char('\n'), KeyModifiers::ALT));
assert_eq!(t.text(), "\n");
}
#[test]
fn control_h_backspace() {
// Test Ctrl+H as backspace