(
buffer: &mut crate::editor::EditorBuffer,
key: crossterm::event::KeyEvent,
)
| 522 | } |
| 523 | |
| 524 | pub fn apply_editor_key( |
| 525 | buffer: &mut crate::editor::EditorBuffer, |
| 526 | key: crossterm::event::KeyEvent, |
| 527 | ) -> bool { |
| 528 | use KeyCode::*; |
| 529 | |
| 530 | match key.code { |
| 531 | Left | Right | Up | Down | Home | End |
| 532 | if !key.modifiers.contains(KeyModifiers::SHIFT) => |
| 533 | { |
| 534 | if let Some(movement) = key_to_buffer_move(key.code, key.modifiers) { |
| 535 | buffer.move_cursor(movement, false); |
| 536 | } |
| 537 | false |
| 538 | } |
| 539 | Backspace if !key.modifiers.contains(KeyModifiers::ALT) => { |
| 540 | buffer.delete_char_backward(); |
| 541 | true |
| 542 | } |
| 543 | Delete if !key.modifiers.contains(KeyModifiers::ALT) => { |
| 544 | buffer.delete_char_forward(); |
| 545 | true |
| 546 | } |
| 547 | Char(c) |
| 548 | if !key.modifiers.contains(KeyModifiers::CONTROL) |
| 549 | && !key.modifiers.contains(KeyModifiers::ALT) |
| 550 | && !key.modifiers.contains(KeyModifiers::SUPER) => |
| 551 | { |
| 552 | let pair = match c { |
| 553 | '(' => Some("()"), |
| 554 | '[' => Some("[]"), |
| 555 | '{' => Some("{}"), |
| 556 | '"' => Some("\"\""), |
| 557 | '\'' => Some("''"), |
| 558 | _ => None, |
| 559 | }; |
| 560 | |
| 561 | if let Some(pair) = pair { |
| 562 | buffer.insert_str(pair); |
| 563 | buffer.move_cursor(BufferMove::Left, false); |
| 564 | } else { |
| 565 | buffer.insert_char(c); |
| 566 | } |
| 567 | true |
| 568 | } |
| 569 | _ => false, |
| 570 | } |
| 571 | } |
no test coverage detected