Skip to content

Commit 84abb39

Browse files
committed
Don't repeat Left/Right in multiple mods
1 parent 38f6536 commit 84abb39

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/page.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ use crate::fl;
22
use crate::picker::{LAYERS, SCANCODE_LABELS};
33
use backend::{Key, Keycode, Mods};
44

5+
static MOD_LABELS: &[(Mods, &str)] = &[
6+
(Mods::CTRL, "Ctrl"),
7+
(Mods::SHIFT, "Shift"),
8+
(Mods::ALT, "Alt"),
9+
(Mods::SUPER, "Super"),
10+
];
11+
512
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
613
pub enum Page {
714
Layer1,
@@ -115,13 +122,25 @@ fn keycode_label(keycode: &Keycode) -> Option<Vec<String>> {
115122
}
116123

117124
fn mods_label(mods: Mods) -> String {
118-
let mut label = String::new();
119-
for name in mods.mod_names() {
120-
let mod_label = SCANCODE_LABELS.get(name).map_or("", String::as_str);
121-
if !label.is_empty() {
122-
label.push_str(" + ");
125+
if mods.is_empty() {
126+
return String::new();
127+
}
128+
129+
let mut label = if mods.contains(Mods::RIGHT) {
130+
"Right "
131+
} else {
132+
"Left "
133+
}
134+
.to_string();
135+
let mut first = true;
136+
for (mod_, mod_label) in MOD_LABELS {
137+
if mods.contains(*mod_) {
138+
if !first {
139+
label.push_str(" + ");
140+
}
141+
label.push_str(mod_label);
142+
first = false;
123143
}
124-
label.push_str(mod_label);
125144
}
126145
label
127146
}

0 commit comments

Comments
 (0)