fixes to linux terminal problems
- SHA
492a7b2d17a51db292e144f9af6b8ac7ec032ac4- Parents
-
a71b8b2 - Tree
f5af71e
492a7b2
492a7b2d17a51db292e144f9af6b8ac7ec032ac4a71b8b2
f5af71e| Status | File | + | - |
|---|---|---|---|
| M |
src/editor/state.rs
|
9 | 3 |
| M |
src/input/key.rs
|
11 | 1 |
src/editor/state.rsmodified@@ -1,6 +1,6 @@ | ||
| 1 | 1 | use anyhow::Result; |
| 2 | 2 | use arboard::Clipboard; |
| 3 | -use crossterm::event::{self, Event, KeyEvent, MouseEvent}; | |
| 3 | +use crossterm::event::{self, Event, KeyEvent, KeyEventKind, MouseEvent}; | |
| 4 | 4 | use std::path::{Path, PathBuf}; |
| 5 | 5 | use std::time::{Duration, Instant}; |
| 6 | 6 | |
@@ -811,7 +811,10 @@ impl Editor { | ||
| 811 | 811 | // This balances responsiveness with CPU usage |
| 812 | 812 | if event::poll(Duration::from_millis(50))? { |
| 813 | 813 | match event::read()? { |
| 814 | - Event::Key(key_event) => self.process_key(key_event)?, | |
| 814 | + // Only process key presses and repeats, not releases | |
| 815 | + Event::Key(key_event) if key_event.kind != KeyEventKind::Release => { | |
| 816 | + self.process_key(key_event)? | |
| 817 | + } | |
| 815 | 818 | Event::Mouse(mouse_event) => self.process_mouse(mouse_event)?, |
| 816 | 819 | Event::Resize(cols, rows) => { |
| 817 | 820 | self.screen.cols = cols; |
@@ -825,7 +828,10 @@ impl Editor { | ||
| 825 | 828 | // Process any additional queued events before rendering |
| 826 | 829 | while event::poll(Duration::from_millis(0))? { |
| 827 | 830 | match event::read()? { |
| 828 | - Event::Key(key_event) => self.process_key(key_event)?, | |
| 831 | + // Only process key presses and repeats, not releases | |
| 832 | + Event::Key(key_event) if key_event.kind != KeyEventKind::Release => { | |
| 833 | + self.process_key(key_event)? | |
| 834 | + } | |
| 829 | 835 | Event::Mouse(mouse_event) => self.process_mouse(mouse_event)?, |
| 830 | 836 | Event::Resize(cols, rows) => { |
| 831 | 837 | self.screen.cols = cols; |
src/input/key.rsmodified@@ -44,7 +44,17 @@ impl Key { | ||
| 44 | 44 | pub fn from_crossterm(event: KeyEvent) -> (Self, Modifiers) { |
| 45 | 45 | let modifiers = Modifiers::from(event.modifiers); |
| 46 | 46 | let key = match event.code { |
| 47 | - KeyCode::Char(c) => Key::Char(c), | |
| 47 | + KeyCode::Char(c) => { | |
| 48 | + // If shift is pressed and character is lowercase alphabetic, | |
| 49 | + // uppercase it. This handles terminals that don't support | |
| 50 | + // REPORT_ALTERNATE_KEYS properly (which would report 'A' directly). | |
| 51 | + let c = if modifiers.shift && c.is_ascii_lowercase() { | |
| 52 | + c.to_ascii_uppercase() | |
| 53 | + } else { | |
| 54 | + c | |
| 55 | + }; | |
| 56 | + Key::Char(c) | |
| 57 | + } | |
| 48 | 58 | KeyCode::Backspace => Key::Backspace, |
| 49 | 59 | KeyCode::Delete => Key::Delete, |
| 50 | 60 | KeyCode::Enter => Key::Enter, |