From 3d7a63293803373723475e4be5a358f05f2c93d1 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Mon, 24 Jul 2023 15:03:45 +0200 Subject: [PATCH] prevent files jumping when commited --- src-tauri/src/virtual_branches/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/virtual_branches/mod.rs b/src-tauri/src/virtual_branches/mod.rs index fa9982bfc..48ded6afe 100644 --- a/src-tauri/src/virtual_branches/mod.rs +++ b/src-tauri/src/virtual_branches/mod.rs @@ -789,7 +789,7 @@ pub fn list_virtual_branches( .context("failed to diff trees")?; let non_commited_hunks_by_filepath = hunks_by_filepath(project_repository, &diff); - non_commited_hunks_by_filepath + let mut vfiles = non_commited_hunks_by_filepath .into_iter() .map(|(file_path, non_commited_hunks)| VirtualBranchFile { id: file_path.display().to_string(), @@ -819,7 +819,16 @@ pub fn list_virtual_branches( ) .unwrap_or(false), }) - .collect::>() + .collect::>(); + + // stable files sort using virtual files position + vfiles.sort_by(|a, b| { + let pos_a = files.iter().position(|f| f.id == a.id).unwrap_or(0); + let pos_b = files.iter().position(|f| f.id == b.id).unwrap_or(0); + pos_a.cmp(&pos_b) + }); + + vfiles } else { files };