VNOX-Client/patches/i-slint-backend-winit/keyboard_shortcuts.rs
loki5512344 f04691c3cd
chore(client): checkpoint deployed features and unfinished server management
User requested a checkpoint and stopped all agents. Deployed artifacts remain the last verified releases; unfinished settings/categories/forums are preserved as WIP. See TODO/roadmap for verification and remaining release/updater work.
2026-11-01 15:31:21 +01:00

74 lines
2.2 KiB
Rust
Vendored
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright © VNOX Contributors
// SPDX-License-Identifier: GPL-3.0-only
/// Translate standard Ctrl shortcuts without replacing normal layout text.
/// Latin layouts retain their logical letters (including AZERTY/Dvorak).
pub(crate) fn shortcut_letter(
logical: &str,
physical: Option<char>,
control: bool,
alt_or_altgr: bool,
meta: bool,
) -> Option<char> {
if !control || alt_or_altgr || meta {
return None;
}
let mut chars = logical.chars();
let letter = chars.next()?;
if chars.next().is_some() || !letter.is_alphabetic() {
return None;
}
let letter = if letter.is_ascii() {
letter.to_ascii_lowercase()
} else {
physical?
};
"acvxyzfspr".contains(letter).then_some(letter)
}
#[cfg(test)]
mod tests {
use super::shortcut_letter;
#[test]
fn russian_control_shortcuts_use_physical_letters() {
for (logical, physical) in [("м", 'v'), ("с", 'c'), ("ч", 'x'), ("ф", 'a'), ("я", 'z')]
{
assert_eq!(
shortcut_letter(logical, Some(physical), true, false, false),
Some(physical)
);
}
}
#[test]
fn ordinary_cyrillic_and_altgr_are_untouched() {
assert_eq!(shortcut_letter("м", Some('v'), false, false, false), None);
assert_eq!(shortcut_letter("м", Some('v'), true, true, false), None);
assert_eq!(shortcut_letter("м", Some('v'), true, false, true), None);
}
#[test]
fn latin_layouts_use_logical_shortcuts_and_ignore_physical_positions() {
assert_eq!(
shortcut_letter("a", Some('q'), true, false, false),
Some('a')
);
assert_eq!(shortcut_letter("q", Some('a'), true, false, false), None);
assert_eq!(
shortcut_letter("V", Some('v'), true, false, false),
Some('v')
);
}
#[test]
fn dead_composed_and_non_letter_keys_are_untouched() {
for logical in ["", "´", "éa", "\u{0011}", ";"] {
assert_eq!(
shortcut_letter(logical, Some('v'), true, false, false),
None
);
}
assert_eq!(shortcut_letter("м", None, true, false, false), None);
}
}