Move key codepoint computation to key event

For the next commit.
This commit is contained in:
Johannes Altmanninger
2025-09-20 09:12:55 +02:00
parent 9bf58abcae
commit 8d12dfe065
2 changed files with 22 additions and 24 deletions

View File

@@ -16,7 +16,7 @@
use crate::universal_notifier::default_notifier;
use crate::wchar::{encode_byte_to_char, prelude::*};
use crate::wutil::encoding::{mbrtowc, mbstate_t, zero_mbstate};
use crate::wutil::fish_wcstol;
use crate::wutil::{fish_is_pua, fish_wcstol};
use std::cell::{RefCell, RefMut};
use std::collections::VecDeque;
use std::mem::MaybeUninit;
@@ -169,6 +169,26 @@ pub(crate) fn from_raw(codepoint: char) -> Self {
pub fn from_single_byte(c: u8) -> Self {
Self::from(Key::from_single_byte(c))
}
pub(crate) fn codepoint_text(&self) -> Option<char> {
if self.modifiers.is_some() {
return None;
}
let c = self.codepoint;
if c == key::Space {
return Some(' ');
}
if c == key::Enter {
return Some('\n');
}
if c == key::Tab {
return Some('\t');
}
if fish_is_pua(c) || u32::from(c) <= 27 {
return None;
}
Some(c)
}
}
impl From<Key> for KeyEvent {

View File

@@ -7,7 +7,7 @@
future_feature_flags::{test as feature_test, FeatureFlag},
reader::safe_get_terminal_mode_on_startup,
wchar::{decode_byte_from_char, prelude::*},
wutil::{fish_is_pua, fish_wcstoul},
wutil::fish_wcstoul,
};
pub(crate) const Backspace: char = '\u{F500}'; // below ENCODE_DIRECT_BASE
@@ -353,28 +353,6 @@ pub(crate) fn canonicalize_raw_escapes(keys: Vec<Key>) -> Vec<Key> {
canonical
}
impl Key {
pub(crate) fn codepoint_text(&self) -> Option<char> {
if self.modifiers.is_some() {
return None;
}
let c = self.codepoint;
if c == Space {
return Some(' ');
}
if c == Enter {
return Some('\n');
}
if c == Tab {
return Some('\t');
}
if fish_is_pua(c) || u32::from(c) <= 27 {
return None;
}
Some(c)
}
}
impl std::fmt::Display for Key {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
WString::from(*self).fmt(f)