diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-07 03:26:04 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-07 03:26:04 +0530 |
commit | 8d21dbb3a44aeaf3989c25d9555559b34632f8c7 (patch) | |
tree | e3d8fbf0933564906582734701b4cdf15289dba5 /src/interactive/widgets | |
parent | 5cff69c47a5b92017e6b1c55a35fd97f08ab3181 (diff) |
maintain sorting even though we have a map - each render must allocate now
Maybe it's better to just spend the time searching through an array,
which we could sort before and do a bisection.
... sounds better actually.
Even though... that might even be more expensive if the sorting is
done every time. Just stick to a list, huh?
Diffstat (limited to 'src/interactive/widgets')
-rw-r--r-- | src/interactive/widgets/mark.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index 8479741..7d50991 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -45,11 +45,19 @@ impl MarkPane { self.marked.remove(&index); } else { if let Some(e) = tree.node_weight(index) { + let sorting_index = self + .marked + .values() + .map(|v| v.index) + .max() + .unwrap_or(0) + .wrapping_add(1); self.marked.insert( index, EntryMark { size: e.size, path: path_of(tree, index), + index: sorting_index, }, ); } @@ -85,8 +93,9 @@ impl MarkPane { let MarkPaneProps { border_style } = props.borrow(); let marked: &_ = &self.marked; + let title = format!("Marked Entries: {}", marked.len()); let block = Block::default() - .title("Marked Entries") + .title(&title) .border_style(*border_style) .borders(Borders::ALL); let entry_in_view = self @@ -96,7 +105,7 @@ impl MarkPane { let selected = self.selected; let entries = marked .values() - .sorted_by_key(|v| &v.path) + .sorted_by_key(|v| &v.index) .enumerate() .map(|(idx, v)| { let modifier = match selected { |