Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
601 changes: 545 additions & 56 deletions crates/disktree-app/src/marks.rs

Large diffs are not rendered by default.

55 changes: 22 additions & 33 deletions crates/disktree-app/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,25 +2130,14 @@ impl Disktree {
let path = target.path.clone();
if self.marks.toggle(target) {
self.space_baseline = self.space_baseline.or(self.space);
let inside: Vec<PathBuf> = self
.marks
.items()
.iter()
.filter(|item| {
item.path != path && item.path.starts_with(&path)
})
.map(|item| item.path.clone())
.collect();
for inner in &inside {
self.marks.remove(inner);
}
if !inside.is_empty() {
let inside = self.marks.absorb(&path);
if inside > 0 {
self.notice = Some((
format!(
"{} now covers {} mark{} inside it",
display_path(&path, self.home.as_deref()),
inside.len(),
if inside.len() == 1 { "" } else { "s" }
inside,
if inside == 1 { "" } else { "s" }
),
Status::Neutral,
));
Expand All @@ -2159,12 +2148,7 @@ impl Disktree {

/// The marked directory `path` is inside, if any; never `path` itself.
pub fn marked_ancestor(&self, path: &Path) -> Option<PathBuf> {
self.marks
.items()
.iter()
.filter(|item| item.path != path && path.starts_with(&item.path))
.map(|item| item.path.clone())
.min_by_key(|ancestor| ancestor.as_os_str().len())
self.marks.ancestor(path).map(Path::to_path_buf)
}

pub fn target_at(&self, crumbs: &[usize]) -> Option<Target> {
Expand All @@ -2191,6 +2175,8 @@ impl Disktree {

/// The plan the review screen shows and the removal runs.
pub fn plan(&self) -> Plan {
#[cfg(test)]
crate::marks::work::PLANS.set(crate::marks::work::PLANS.get() + 1);
if self.remote.is_some() {
// Never judge remote paths against this machine's filesystem.
// This is an export selection, not an executable removal plan.
Expand Down Expand Up @@ -2221,19 +2207,17 @@ impl Disktree {
/// to draw, and the marked/hidden/selected state of every tile is decided
/// here, where the tree and the marks are both at hand.
pub fn prepare(&mut self) -> Mosaic {
#[cfg(test)]
crate::marks::work::FRAMES.set(crate::marks::work::FRAMES.get() + 1);
let metric = self.options.metric;
let view = self.view;
let hovered = self.hovered.clone();
let selected = self.selected.clone();

// Marks are paths; the mosaic thinks in crumbs. Resolve once per frame
// rather than building a path for every tile.
let mut marked: FxHashSet<Vec<usize>> = FxHashSet::default();
for item in self.marks.items() {
if let Some(crumbs) = self.crumbs_for_path(&item.path) {
marked.insert(crumbs);
}
}
let marked = self.tree.as_ref().map_or_else(
|| Arc::new(FxHashSet::default()),
|tree| self.marks.crumbs(&self.root_path, tree, metric),
);

let Some(tiles) = self.layout().map(<[Tile]>::to_vec) else {
return Mosaic {
Expand All @@ -2249,6 +2233,8 @@ impl Disktree {
let mut decorations = Vec::with_capacity(tiles.len());
let mut labels = Vec::new();
for tile in &tiles {
#[cfg(test)]
crate::marks::work::TILES.set(crate::marks::work::TILES.get() + 1);
let crumbs = tile.crumbs();
let node = match &tile.kind {
TileKind::Node { crumbs } => self.node_at(crumbs),
Expand Down Expand Up @@ -2356,10 +2342,11 @@ impl Disktree {
let mut crumbs = Vec::new();
for component in relative.components() {
let name = component.as_os_str().to_string_lossy();
let index = node
.children
.iter()
.position(|child| child.name.as_ref() == name)?;
let index = node.children.iter().position(|child| {
#[cfg(test)]
crate::marks::work::step();
child.name.as_ref() == name
})?;
crumbs.push(index);
node = node.child(index)?;
}
Expand Down Expand Up @@ -3713,6 +3700,8 @@ impl Render for Disktree {
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> impl gpui_kit::IntoElement {
#[cfg(test)]
crate::marks::work::RENDERS.set(crate::marks::work::RENDERS.get() + 1);
self.rem = window.rem_size().as_f32();
self.tick_transition(window);
// The titlebar names the directory on screen, however it got there:
Expand Down
Loading
Loading