From 83d67a663b7eea1a4ab80688574335fa91566c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Wed, 2 Nov 2022 18:35:10 +0100 Subject: [PATCH] fix: keep order of keyboard mappings in prefs view stable --- services/status/src/preferences.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/services/status/src/preferences.rs b/services/status/src/preferences.rs index 12e5d8b9b..d819e54da 100644 --- a/services/status/src/preferences.rs +++ b/services/status/src/preferences.rs @@ -1,7 +1,7 @@ use crate::wifi; use locales::t; use num_traits::*; -use std::{fmt::Display, collections::HashMap}; +use std::fmt::Display; use userprefs::Manager; pub trait PrefHandler { @@ -238,15 +238,15 @@ impl DevicePrefs { fn keyboard_layout(&mut self) -> Result<(), DevicePrefsError> { let kl = self.up.keyboard_layout_or_default()?; - let mut mappings = HashMap::new(); - - mappings.insert("QWERTY", 0 as usize); - mappings.insert("AZERTY", 1); - mappings.insert("QWERTZ", 2); - mappings.insert("Dvorak", 3); + let mappings = vec![ + "QWERTY", + "AZERTY", + "QWERTZ", + "Dvorak", + ]; self.modals - .add_list(mappings.keys().cloned().collect()) + .add_list(mappings.clone()) .unwrap(); let new_result = self @@ -254,7 +254,10 @@ impl DevicePrefs { .get_radiobutton(&format!("Current layout: {}", keyboard::KeyMap::from(kl))) .unwrap(); - let new_result = mappings[new_result.as_str()]; + let new_result = match mappings.iter().position(|&elem| elem == new_result.as_str()) { + Some(val) => val, + None => 0, + }; self.up.set_keyboard_layout(new_result)?;