Reorder set_mark and with_mark

pull/56/head
Takashi Kokubun 3 years ago
parent f7256c6c88
commit 343204607c
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD

@ -14,10 +14,10 @@ pub enum Action {
Remap(HashMap<KeyPress, Vec<Action>>),
#[serde(deserialize_with = "deserialize_launch")]
Launch(Vec<String>),
#[serde(deserialize_with = "deserialize_with_mark")]
WithMark(KeyPress),
#[serde(deserialize_with = "deserialize_set_mark")]
SetMark(bool),
#[serde(deserialize_with = "deserialize_with_mark")]
WithMark(KeyPress),
}
fn deserialize_remap<'de, D>(deserializer: D) -> Result<HashMap<KeyPress, Vec<Action>>, D::Error>
@ -46,30 +46,30 @@ where
Err(de::Error::custom("not a map with a single \"launch\" key"))
}
fn deserialize_with_mark<'de, D>(deserializer: D) -> Result<KeyPress, D::Error>
fn deserialize_set_mark<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
let mut action = HashMap::<String, KeyPress>::deserialize(deserializer)?;
if let Some(key_press) = action.remove("with_mark") {
let mut action = HashMap::<String, bool>::deserialize(deserializer)?;
if let Some(set) = action.remove("set_mark") {
if action.is_empty() {
return Ok(key_press);
return Ok(set);
}
}
Err(de::Error::custom("not a map with a single \"with_mark\" key"))
Err(de::Error::custom("not a map with a single \"set_mark\" key"))
}
fn deserialize_set_mark<'de, D>(deserializer: D) -> Result<bool, D::Error>
fn deserialize_with_mark<'de, D>(deserializer: D) -> Result<KeyPress, D::Error>
where
D: Deserializer<'de>,
{
let mut action = HashMap::<String, bool>::deserialize(deserializer)?;
if let Some(set) = action.remove("set_mark") {
let mut action = HashMap::<String, KeyPress>::deserialize(deserializer)?;
if let Some(key_press) = action.remove("with_mark") {
if action.is_empty() {
return Ok(set);
return Ok(key_press);
}
}
Err(de::Error::custom("not a map with a single \"set_mark\" key"))
Err(de::Error::custom("not a map with a single \"with_mark\" key"))
}
// Used only for deserializing Vec<Action>

@ -198,8 +198,8 @@ impl EventHandler {
self.override_remap = Some(override_remap)
}
Action::Launch(command) => self.run_command(command.clone()),
Action::WithMark(key_press) => self.send_key_press(&self.with_mark(key_press))?,
Action::SetMark(set) => self.mark_set = *set,
Action::WithMark(key_press) => self.send_key_press(&self.with_mark(key_press))?,
}
Ok(())
}

Loading…
Cancel
Save