Struct TextKeymap

Source
pub struct TextKeymap {
    pub mode: TextInputMode,
    pub platform: PlatformKeymap,
}
Expand description

Maps [KeyEvent] to TextEditAction for a given input mode and platform.

This translator is stateless. It ignores key releases, dead keys, pointer positions, and does not suppress repeated pressed events. Clipboard commands remain host requests rather than direct I/O.

§Examples

use ailloli_ui_text::{PlatformKeymap, TextInputMode, TextKeymap};
let keymap = TextKeymap::for_platform(TextInputMode::SingleLine, PlatformKeymap::LinuxWindows);
assert_eq!(keymap.mode, TextInputMode::SingleLine);
assert_eq!(keymap.platform, PlatformKeymap::LinuxWindows);

Fields§

§mode: TextInputMode

Whether Enter is ignored or translated into newline insertion.

§platform: PlatformKeymap

Modifier used for selection, clipboard, word, and history shortcuts.

Implementations§

Source§

impl TextKeymap

Source

pub fn new(mode: TextInputMode) -> Self

Creates a keymap using PlatformKeymap::current.

§Examples
use ailloli_ui_text::{PlatformKeymap, TextInputMode, TextKeymap};
let keymap = TextKeymap::new(TextInputMode::MultiLine);
assert_eq!(keymap.mode, TextInputMode::MultiLine);
assert_eq!(keymap.platform, PlatformKeymap::current());
Source

pub fn for_platform(mode: TextInputMode, platform: PlatformKeymap) -> Self

Creates a keymap with an explicit, deterministic platform mapping.

This constructor is useful for tests and remote input whose shortcut convention differs from the compilation target.

§Examples
use ailloli_ui_text::{PlatformKeymap, TextInputMode, TextKeymap};
let keymap = TextKeymap::for_platform(TextInputMode::SingleLine, PlatformKeymap::MacOs);
assert_eq!(keymap.platform, PlatformKeymap::MacOs);
Source

pub fn action_for_key(&self, event: &KeyEvent) -> Option<TextEditAction>

Translates a pressed key event into one editing action.

Primary-modifier character shortcuts are ASCII case-insensitive: A/C/X/V, Z (Shift-Z for redo), and Y. Unknown primary characters return None. Left/right become word moves with the primary modifier; Home/End become document moves. Shift extends movement selections. Plain character input prefers event.text over the logical key, allowing composed characters; Alt or Meta suppress it, and named Space falls back to one ASCII space. Enter inserts only in multiline mode. event.repeat is intentionally ignored, so a repeated pressed event maps identically.

§Examples
use ailloli_ui_core::event::{Key, KeyEvent, KeyState, Modifiers};
use ailloli_ui_text::{PlatformKeymap, TextEditAction, TextInputMode, TextKeymap};
let keymap = TextKeymap::for_platform(TextInputMode::SingleLine, PlatformKeymap::LinuxWindows);
let event = KeyEvent {
    state: KeyState::Pressed,
    key: Key::Character("c".into()),
    modifiers: Modifiers { ctrl: true, ..Modifiers::default() },
    repeat: false,
    pointer_pos: None,
    text: None,
};
assert_eq!(keymap.action_for_key(&event), Some(TextEditAction::Copy));

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,