From 212829370f8a15cffb5af883dd0e042f3695a7f1 Mon Sep 17 00:00:00 2001 From: Yongwoo Lee Date: Sun, 20 Oct 2024 12:17:51 +0900 Subject: [PATCH] feat: make result consistent & handle cyclic rename entries & add test contains valid rename and cycle --- yazi-core/src/manager/commands/bulk_rename.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/yazi-core/src/manager/commands/bulk_rename.rs b/yazi-core/src/manager/commands/bulk_rename.rs index c3b94660..c799ac2d 100644 --- a/yazi-core/src/manager/commands/bulk_rename.rs +++ b/yazi-core/src/manager/commands/bulk_rename.rs @@ -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::>(); + 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!("") }; @@ -189,8 +195,14 @@ mod tests { #[rustfmt::skip] cmp( - &[("1", "2"), ("2", "1")], - &[("2", "1"), ("1", "2")] + &[("2", "1"), ("1", "2")], + &[("1", "2"), ("2", "1")] + ); + + #[rustfmt::skip] + cmp( + &[("3", "2"), ("2", "1"), ("1", "3"), ("a", "b"), ("b", "c")], + &[("b", "c"), ("a", "b"), ("1", "3"), ("2", "1"), ("3", "2")] ); } }