Simplify direction logic
This commit is contained in:
parent
3b4e7db912
commit
8b2f5bfeb4
|
@ -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,
|
||||
|
|
24
src/store.rs
24
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue