Skip to content

Commit

Permalink
feat: make result consistent & handle cyclic rename entries
Browse files Browse the repository at this point in the history
  • Loading branch information
yw1ee committed Oct 20, 2024
1 parent b8341e2 commit 90bb7c3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions yazi-core/src/manager/commands/bulk_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ impl Manager {
});

if has_no_incomes.is_empty() {
todo!("Consider cycle")
// Remaining rename set has cycle, so we cannot sort, just return them all
let mut remain = todos.drain().collect::<Vec<_>>();
remain.sort();
sorted.reverse();
sorted.extend(remain);
return sorted;
}

has_no_incomes.sort();
for old in has_no_incomes {
income_map.remove(&old);
let Some(new) = todos.remove(&old) else { unreachable!("") };
Expand Down Expand Up @@ -189,8 +195,8 @@ mod tests {

#[rustfmt::skip]
cmp(
&[("1", "2"), ("2", "1")],
&[("2", "1"), ("1", "2")]
&[("3", "2"), ("2", "1"), ("1", "3")],
&[("1", "3"), ("2", "1"), ("3", "2")]
);
}
}

0 comments on commit 90bb7c3

Please sign in to comment.