Compare commits

...

2 Commits

Author SHA1 Message Date
nick d101367e34 added move_up 2024-10-10 13:14:08 -04:00
nick 44e138d39e added autopsy option 2024-10-10 13:03:26 -04:00
1 changed files with 41 additions and 23 deletions

View File

@ -205,7 +205,6 @@ impl Directory {
let selected_subtree = self.subtree_indices(self.selection());
let sibling_subtree = self.subtree_indices(index);
let delta = if selected_subtree.len() < sibling_subtree.len() {
let select_len = selected_subtree.len();
let sibling_len = sibling_subtree.len();
@ -218,22 +217,38 @@ impl Directory {
*dst = item;
}
sibling_len
} else if selected_subtree.len() == sibling_subtree.len() {
let (selected, sibling) = self.dirs.split_at_mut(index);
self.selection += u16::try_from(sibling_len).unwrap_or(u16::MAX);
}
let len = selected.len();
let lhs = &mut selected[len - selected_subtree.len() .. ];
let rhs = &mut sibling[0 .. sibling_subtree.len()];
fn move_up(&mut self) {
let current_depth = self.selected().depth;
lhs.swap_with_slice(rhs);
selected_subtree.len()
} else {
todo!()
let Some(index) = (0 .. self.selection())
.rev()
.take_while(|&i| self.dirs[i].depth >= current_depth)
.filter(|&i| self.dirs[i].depth == current_depth)
.next()
else {
return
};
self.selection += u16::try_from(delta).unwrap_or(u16::MAX);
let selected_subtree = self.subtree_indices(self.selection());
let sibling_subtree = self.subtree_indices(index);
let select_len = selected_subtree.len();
let sibling_len = sibling_subtree.len();
let selected_copy = self.dirs[selected_subtree].to_owned();
let sibling_copy = self.dirs[sibling_subtree].to_owned();
let back_to_back = selected_copy.into_iter().chain(sibling_copy);
let full_range = index .. index+select_len+sibling_len;
for (dst, item) in self.dirs[full_range].iter_mut().zip(back_to_back) {
*dst = item;
}
self.selection -= u16::try_from(sibling_len).unwrap_or(u16::MAX);
}
fn selected(&self) -> &Item {
@ -332,6 +347,9 @@ impl Directory {
},
KeyCode::Down => {
self.move_down();
},
KeyCode::Up => {
self.move_up();
}
_ => (),
}