Change the L/R syntax from a prefix to a suffix

pull/56/head
Takashi Kokubun 2 years ago
parent 804ad68718
commit a4cf2e75a1
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD

@ -168,8 +168,8 @@ For the `MOD1-` part, the following prefixes can be used (also case-insensitive)
* Windows: `SUPER-`, `WIN-`, `WINDOWS-`
You can use multiple prefixes like `C-M-Shift-a`.
You may also prefix them with `L` or `R` (case-insensitive) so that
remapping is triggered only on a left or right modifier, e.g. `LCtrl-a`.
You may also suffix them with `_L` or `_R` (case-insensitive) so that
remapping is triggered only on a left or right modifier, e.g. `Ctrl_L-a`.
### application

@ -72,11 +72,11 @@ fn parse_modifier(modifier: &str) -> Option<(Modifier, ModifierState)> {
// Everything is case-insensitive
let mut modifier = &modifier.to_uppercase()[..];
let mut modifier_state = ModifierState::Either;
if modifier.starts_with("L") {
modifier = remove_first_char(modifier);
if modifier.ends_with("_L") {
modifier = remove_suffix(modifier);
modifier_state = ModifierState::Left;
} else if modifier.starts_with("R") {
modifier = remove_first_char(modifier);
} else if modifier.ends_with("_R") {
modifier = remove_suffix(modifier);
modifier_state = ModifierState::Right;
}
@ -99,8 +99,9 @@ fn parse_modifier(modifier: &str) -> Option<(Modifier, ModifierState)> {
}
}
fn remove_first_char(string: &str) -> &str {
fn remove_suffix(string: &str) -> &str {
let mut chars = string.chars();
chars.next();
chars.next_back();
chars.next_back();
chars.as_str()
}

@ -66,9 +66,9 @@ fn test_keymap_lr_modifiers() {
keymap:
- name: Global
remap:
LAlt-Enter: RCtrl-Enter
Alt_L-Enter: Ctrl_L-Enter
- remap:
RM-S: LC-S
M_R-S: C_L-S
"})
}

Loading…
Cancel
Save