diff --git a/src/input_common.rs b/src/input_common.rs index 562ff5650..4f3d88ba1 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -19,7 +19,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::collections::VecDeque; use std::mem::MaybeUninit; use std::os::fd::RawFd; @@ -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 { + 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 for KeyEvent { diff --git a/src/key.rs b/src/key.rs index 2a7cad1b6..504951e4f 100644 --- a/src/key.rs +++ b/src/key.rs @@ -5,7 +5,7 @@ fallback::fish_wcwidth, 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 @@ -343,28 +343,6 @@ pub(crate) fn canonicalize_raw_escapes(keys: Vec) -> Vec { canonical } -impl Key { - pub(crate) fn codepoint_text(&self) -> Option { - 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)