1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-10 15:04:32 +03:00

config: refactor to reduce repeating key+mods

Use serde(flatten) so we can reuse KeyNoAction for 3 different structs.
This commit is contained in:
Wez Furlong 2022-03-31 22:38:56 -07:00
parent 27d7666a8d
commit 76cbcb1341
3 changed files with 6 additions and 18 deletions

View File

@ -781,7 +781,7 @@ impl Config {
let mut map = HashMap::new();
for k in &self.keys {
let (key, mods) = k.key.normalize_shift(k.mods);
let (key, mods) = k.key.key.normalize_shift(k.key.mods);
map.insert((key, mods), k.action.clone());
}

View File

@ -880,7 +880,7 @@ impl InputMap {
pub fn is_leader(&self, key: &KeyCode, mods: Modifiers) -> Option<std::time::Duration> {
if let Some(leader) = self.leader.as_ref() {
if leader.key == *key && leader.mods == mods {
if leader.key.key == *key && leader.key.mods == mods {
return Some(std::time::Duration::from_millis(
leader.timeout_milliseconds,
));

View File

@ -20,28 +20,16 @@ impl_lua_conversion!(KeyNoAction);
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Key {
#[serde(deserialize_with = "de_keycode", serialize_with = "ser_keycode")]
pub key: KeyCode,
#[serde(
deserialize_with = "de_modifiers",
serialize_with = "ser_modifiers",
default
)]
pub mods: Modifiers,
#[serde(flatten)]
pub key: KeyNoAction,
pub action: KeyAssignment,
}
impl_lua_conversion!(Key);
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LeaderKey {
#[serde(deserialize_with = "de_keycode", serialize_with = "ser_keycode")]
pub key: KeyCode,
#[serde(
deserialize_with = "de_modifiers",
serialize_with = "ser_modifiers",
default
)]
pub mods: Modifiers,
#[serde(flatten)]
pub key: KeyNoAction,
#[serde(default = "default_leader_timeout")]
pub timeout_milliseconds: u64,
}