diff --git a/src/lib.rs b/src/lib.rs index 6de2d93..872c854 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,7 +116,7 @@ impl Config { } } -#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)] pub enum Direction { #[serde(rename = "up")] Up, diff --git a/src/store.rs b/src/store.rs index be4fd4e..41538d3 100644 --- a/src/store.rs +++ b/src/store.rs @@ -210,21 +210,15 @@ impl Store { let entry_uuid = config.move_entry_path.entry; let direction = config.move_entry_path.direction; - for i in 0..order.len() { - if i + 1 < order.len() { - match direction { - Direction::Up if order[i + 1] == entry_uuid => { - order[i + 1] = order[i]; - order[i] = entry_uuid; - break; - } - Direction::Down if order[i] == entry_uuid => { - order[i] = order[i + 1]; - order[i + 1] = entry_uuid; - break; - } - _ => {} - } + for i in 0..(order.len() - 1) { + if order[i + 1] == entry_uuid && direction == Direction::Up { + order[i + 1] = order[i]; + order[i] = entry_uuid; + break; + } else if order[i] == entry_uuid && direction == Direction::Down { + order[i] = order[i + 1]; + order[i + 1] = entry_uuid; + break; } }