diff options
Diffstat (limited to 'src/ui/sidebar.rs')
| -rw-r--r-- | src/ui/sidebar.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/ui/sidebar.rs b/src/ui/sidebar.rs index 15c0a37e..ffb93f22 100644 --- a/src/ui/sidebar.rs +++ b/src/ui/sidebar.rs @@ -272,7 +272,11 @@ pub(crate) fn workspace_parent_group_state( }) } -fn grouped_child_display_label(label: &str, branch: Option<&str>, has_custom_name: bool) -> String { +pub(crate) fn grouped_child_display_label( + label: &str, + branch: Option<&str>, + has_custom_name: bool, +) -> String { if has_custom_name { return label.to_string(); } @@ -290,7 +294,7 @@ pub(crate) enum WorkspaceListEntry { Workspace { ws_idx: usize, indented: bool }, } -fn next_entry_is_indented_workspace(entries: &[WorkspaceListEntry], idx: usize) -> bool { +pub(crate) fn next_entry_is_indented_workspace(entries: &[WorkspaceListEntry], idx: usize) -> bool { matches!( entries.get(idx.saturating_add(1)), Some(WorkspaceListEntry::Workspace { indented: true, .. }) @@ -313,6 +317,17 @@ pub(crate) fn normalized_workspace_scroll(app: &AppState, area: Rect, requested: } pub(crate) fn workspace_list_entries(app: &AppState) -> Vec<WorkspaceListEntry> { + workspace_list_entries_inner(app, false) +} + +/// Like [`workspace_list_entries`] but always expands worktree groups, ignoring +/// `collapsed_space_keys`. The mobile switcher has no collapse affordance and +/// always shows the full worktree tree. +pub(crate) fn workspace_list_entries_expanded(app: &AppState) -> Vec<WorkspaceListEntry> { + workspace_list_entries_inner(app, true) +} + +fn workspace_list_entries_inner(app: &AppState, force_expanded: bool) -> Vec<WorkspaceListEntry> { let mut members_by_key = std::collections::HashMap::<String, Vec<usize>>::new(); for (ws_idx, ws) in app.workspaces.iter().enumerate() { if let Some(space) = ws.worktree_space() { @@ -381,7 +396,7 @@ pub(crate) fn workspace_list_entries(app: &AppState) -> Vec<WorkspaceListEntry> }); continue; }; - let collapsed = app.collapsed_space_keys.contains(&space.key); + let collapsed = !force_expanded && app.collapsed_space_keys.contains(&space.key); entries.push(WorkspaceListEntry::Workspace { ws_idx: parent_idx, indented: false, |
