mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-29 18:51:15 -03:00
Move key codepoint computation to key event
For the next commit.
(cherry picked from commit 8d12dfe065)
This commit is contained in:
@@ -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<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 {
|
||||
|
||||
24
src/key.rs
24
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<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)
|
||||
|
||||
Reference in New Issue
Block a user