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: TextInputModeWhether Enter is ignored or translated into newline insertion.
platform: PlatformKeymapModifier used for selection, clipboard, word, and history shortcuts.
Implementations§
Source§impl TextKeymap
impl TextKeymap
Sourcepub fn new(mode: TextInputMode) -> Self
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());Sourcepub fn for_platform(mode: TextInputMode, platform: PlatformKeymap) -> Self
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);Sourcepub fn action_for_key(&self, event: &KeyEvent) -> Option<TextEditAction>
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));