Alt chords as production read them: the type editor claims its Alt+digit character chords (bullet, paragraph, section, trademark), which the framework's Windows Alt-code entry otherwise takes, as production read codes from the keypad only; a tool that takes a lone Alt tap (the Quick Pen switching its action) says so to the canvas host

This commit is contained in:
bflatastic
2026-11-23 09:58:32 +07:00
parent 834c781c36
commit 1f561ca7f0
2 changed files with 21 additions and 0 deletions
@@ -388,6 +388,9 @@ impl CanvasTool for SessionTool<'_> {
if claim(&mut app, EngineKey::Left) {
claims = claims.nudges();
}
if claim(&mut app, EngineKey::AltTap) {
claims = claims.alt_tap();
}
claims
}
+18
View File
@@ -300,6 +300,24 @@ impl Component for TypeEditor<'_> {
while let Some((command, _)) = cx.take_command::<TypeEditorCommand>() {
fired.push(command);
}
// Windows' Alt-code entry takes every Alt+digit no focused component claims, top-row digits too; production
// read codes from the keypad only, so the character commands claim their Alt+digit chords and run them here.
let digit_chords: Vec<(craft::keymap::Chord, TypeEditorCommand)> = TypeEditorCommand::defs()
.unwrap_or_default()
.iter()
.filter_map(|def| {
let command = TypeEditorCommand::from_ref(&def.command).filter(|c| c.character().is_some())?;
let chord = cx.resolve_command(def.command.clone())?.chord?;
(chord.mods == craft::keymap::Mods::ALT && chord.key.is_digit()).then_some((chord, command))
})
.collect();
let chords: Vec<_> = digit_chords.iter().map(|(chord, _)| *chord).collect();
for &chord in &chords {
cx.claim(chord);
}
while let Some(chord) = cx.take_first_claimed(&chords) {
fired.extend(digit_chords.iter().find(|(c, _)| *c == chord).map(|(_, command)| *command));
}
// A new edit takes the keys ([`show`]); a click away loses them.
if !cx.appeared() && !cx.is_focused() {
keep_marked_text(self.app);