git_ui: Allow collapsing the commit editor and commit details (#63236)

## Summary

- The commit message editor in the Git panel is pinned to six lines and
its only two controls both make it *larger* — one fills the panel, the
other opens the modal. Anyone who commits from a terminal pays for an
input they never use, and the Changes list is what gets squeezed.
- In the Git Graph detail panel, the author metadata and the commit
message render at a fixed size above the changed-files list, so
shortening the panel (e.g. dragging the terminal up) hides the file list
entirely.

## Changes

**Git panel — collapsible commit editor**

- New `git::ToggleCommitEditor` action.
- A chevron beside the commit button hides the editor down to a thin
bar; the commit button row stays available.
- State persists per workspace via `SerializedGitPanel`, seeded from a
new `git_panel.commit_editor` setting (`expanded` | `collapsed`, default
`expanded`).
- Collapsing clears the fill state — a hidden editor cannot also fill
the panel.
- `activation_focus_handle` no longer focuses an editor that isn't
rendered.

**Git Graph — collapsible commit details**

- A disclosure folds the author metadata (avatar, refs, email, SHA,
provider link) down to a single author + short-sha line.
- A second disclosure folds the commit message body.
- The changed-files container is already `flex_1().min_h_0()`, so it
reclaims the freed space with no other layout change.

**Settings plumbing**

- `GitPanelCommitEditor` in `settings_content`, wired through
`GitPanelSettings`, `assets/settings/default.json`, the settings UI, and
`docs/src/reference/all-settings.md`.

## Test plan

- [x] `test_toggle_commit_editor_collapsed` added, covering the toggle,
persistence of the flag, and the fill/collapse exclusion.
- [x] Manually verified in a dev build: chevron hides and restores the
editor, Changes list expands into the freed space, action appears in the
command palette, state survives a restart, and the `collapsed` setting
seeds a new workspace.
- [x] Manually verified both disclosures in the Git Graph detail panel
with the panel shortened, including that the collapse state survives
selecting a different commit.

Release Notes:

- Improved the Git panel by allowing the commit message editor to be
collapsed, and the Git Graph commit details by making the metadata and
commit message sections collapsible.

### Evidance Test
| Expand | Collapse | Settings Git Panel |
| ------- | --------- | ------------------ |
| <img width="675" height="965" alt="Screenshot 2026-08-26 at 15 00 46"
src="https://github.com/user-attachments/assets/70c56d02-35fc-45ac-988c-24ccd6d1a19e"
/> | <img width="661" height="962" alt="Screenshot 2026-08-26 at 15 00
57"
src="https://github.com/user-attachments/assets/2c32fa5d-30fc-4f35-8323-afbc2a031210"
/> | <img width="1041" height="956" alt="Screenshot 2026-08-26 at 16 50
40"
src="https://github.com/user-attachments/assets/67f166b6-5cd9-4430-bba3-fa765715c557"
/> |

---------

Co-authored-by: Christopher Biscardi <chris@christopherbiscardi.com>
This commit is contained in:
mulham
2026-10-02 17:25:11 +00:00
committed by GitHub
parent 57af58b3ad
commit c83abe7d0e
9 changed files with 447 additions and 177 deletions
+5
View File
@@ -1147,6 +1147,11 @@
// Choices: project_diff, file_diff, view_file
// Default: project_diff
"entry_primary_click_action": "project_diff",
// Whether the commit message editor is shown in the git panel by default.
//
// Choices: expanded, collapsed
// Default: expanded
"commit_editor": "expanded",
},
"agent": {
// Whether the inline assistant should use streaming tools, when available
+2
View File
@@ -126,6 +126,8 @@ actions!(
/// Toggles whether the commit message editor fills all the available
/// vertical space within the git panel.
ToggleFillCommitEditor,
/// Toggles whether the commit message editor is shown in the git panel.
ToggleCommitEditor,
/// Generates a commit message using AI.
GenerateCommitMessage,
/// Initializes a new git repository.
+223 -142
View File
@@ -49,7 +49,7 @@ use zed_actions::{
use theme::AccentColors;
use time::{OffsetDateTime, UtcOffset, format_description::BorrowedFormatItem};
use ui::{
Chip, ColumnWidthConfig, CommonAnimationExt as _, ContextMenu, DiffStat, Divider,
Chip, ColumnWidthConfig, CommonAnimationExt as _, ContextMenu, DiffStat, Disclosure, Divider,
HeaderResizeInfo, HighlightedLabel, IndentGuideColors, ListItem, ListItemSpacing,
RedistributableColumnsState, ScrollableHandle, Table, TableInteractionState,
TableRenderContext, TableResizeBehavior, Tooltip, WithScrollbar, bind_redistributable_columns,
@@ -1327,6 +1327,8 @@ pub struct GitGraph {
repo_id: RepositoryId,
changed_files_scroll_handle: UniformListScrollHandle,
changed_files_view_mode: ChangedFilesViewMode,
commit_details_metadata_collapsed: bool,
commit_details_message_collapsed: bool,
changed_files_expanded_dirs: HashMap<RepoPath, bool>,
pending_select_sha: Option<Oid>,
nav_history: Option<ItemNavHistory>,
@@ -1574,6 +1576,8 @@ impl GitGraph {
repo_id,
changed_files_scroll_handle: UniformListScrollHandle::new(),
changed_files_view_mode: ChangedFilesViewMode::default(),
commit_details_metadata_collapsed: false,
commit_details_message_collapsed: false,
changed_files_expanded_dirs: HashMap::default(),
pending_select_sha: None,
nav_history: None,
@@ -2715,6 +2719,7 @@ impl GitGraph {
});
let full_sha: SharedString = commit_entry.data.sha.to_string().into();
let short_sha: SharedString = full_sha.chars().take(7).collect::<String>().into();
let ref_names = commit_entry.data.ref_names.clone();
let head_branch_name: Option<SharedString> = repository
@@ -2848,69 +2853,168 @@ impl GitGraph {
),
)
.child(
v_flex()
.py_1()
.w_full()
.items_center()
.child(avatar)
.child(Label::new(author_name).mt_1p5())
.child(
Label::new(date_string)
.color(Color::Muted)
.size(LabelSize::Small),
),
)
.children((!ref_names.is_empty()).then(|| {
h_flex().gap_1().flex_wrap().justify_center().children(
ref_names.iter().map(|name| {
let is_head = Self::is_head_ref(name.as_ref(), &head_branch_name);
self.render_ref_chip(name, accent_color, is_head, selected_idx, cx)
}),
)
}))
.child(
v_flex()
.ml_neg_1()
.gap_1p5()
.when(!author_email.is_empty(), |this| {
let copied_state: Entity<CopiedState> = window.use_keyed_state(
"author-email-copy",
cx,
CopiedState::new,
);
let is_copied = copied_state.read(cx).is_copied();
let (icon, icon_color, tooltip_label) = if is_copied {
(IconName::Check, Color::Success, "Email Copied!")
div().absolute().top_2().left_2().child(
Disclosure::new(
"toggle-commit-metadata",
!self.commit_details_metadata_collapsed,
)
.tooltip({
let label = if self.commit_details_metadata_collapsed {
"Show Commit Details"
} else {
(IconName::Envelope, Color::Muted, "Copy Email")
"Hide Commit Details"
};
move |_window, cx: &mut App| Tooltip::simple(label, cx)
})
.on_click(cx.listener(|this, _, _, cx| {
this.commit_details_metadata_collapsed =
!this.commit_details_metadata_collapsed;
cx.notify();
})),
),
)
.map(|this| {
if self.commit_details_metadata_collapsed {
return this.child(
h_flex()
.w_full()
.px_6()
.gap_1()
.justify_center()
.overflow_hidden()
.child(
Label::new(author_name).size(LabelSize::Small).truncate(),
)
.child(
Label::new(short_sha)
.size(LabelSize::Small)
.color(Color::Muted),
),
);
}
this.child(
v_flex()
.py_1()
.w_full()
.items_center()
.child(avatar)
.child(Label::new(author_name).mt_1p5())
.child(
Label::new(date_string)
.color(Color::Muted)
.size(LabelSize::Small),
),
)
.children((!ref_names.is_empty()).then(|| {
h_flex().gap_1().flex_wrap().justify_center().children(
ref_names.iter().map(|name| {
let is_head =
Self::is_head_ref(name.as_ref(), &head_branch_name);
self.render_ref_chip(
name,
accent_color,
is_head,
selected_idx,
cx,
)
}),
)
}))
.child(
v_flex()
.ml_neg_1()
.gap_1p5()
.when(!author_email.is_empty(), |this| {
let copied_state: Entity<CopiedState> = window.use_keyed_state(
"author-email-copy",
cx,
CopiedState::new,
);
let is_copied = copied_state.read(cx).is_copied();
let copy_email = author_email.clone();
let author_email_for_tooltip = author_email.clone();
let (icon, icon_color, tooltip_label) = if is_copied {
(IconName::Check, Color::Success, "Email Copied!")
} else {
(IconName::Envelope, Color::Muted, "Copy Email")
};
this.child(
Button::new("author-email-copy", author_email.clone())
let copy_email = author_email.clone();
let author_email_for_tooltip = author_email.clone();
this.child(
Button::new("author-email-copy", author_email.clone())
.start_icon(
Icon::new(icon)
.size(IconSize::Small)
.color(icon_color),
)
.label_size(LabelSize::Small)
.truncate(true)
.color(Color::Muted)
.tooltip(move |_, cx| {
Tooltip::with_meta(
tooltip_label,
None,
author_email_for_tooltip.clone(),
cx,
)
})
.on_click(move |_, _, cx| {
copied_state.update(cx, |state, _cx| {
state.mark_copied();
});
cx.write_to_clipboard(ClipboardItem::new_string(
copy_email.to_string(),
));
let state_id = copied_state.entity_id();
cx.spawn(async move |cx| {
cx.background_executor()
.timer(COPIED_STATE_DURATION)
.await;
cx.update(|cx| {
cx.notify(state_id);
})
})
.detach();
}),
)
})
.child({
let copy_sha = full_sha.clone();
let copied_state: Entity<CopiedState> =
window.use_keyed_state("sha-copy", cx, CopiedState::new);
let is_copied = copied_state.read(cx).is_copied();
let (icon, icon_color, tooltip_label) = if is_copied {
(IconName::Check, Color::Success, "Commit SHA Copied!")
} else {
(IconName::Hash, Color::Muted, "Copy Commit SHA")
};
Button::new("sha-button", &full_sha)
.start_icon(
Icon::new(icon).size(IconSize::Small).color(icon_color),
)
.label_size(LabelSize::Small)
.truncate(true)
.color(Color::Muted)
.tooltip(move |_, cx| {
Tooltip::with_meta(
tooltip_label,
None,
author_email_for_tooltip.clone(),
cx,
)
.tooltip({
let full_sha = full_sha.clone();
move |_, cx| {
Tooltip::with_meta(
tooltip_label,
None,
full_sha.clone(),
cx,
)
}
})
.on_click(move |_, _, cx| {
copied_state.update(cx, |state, _cx| {
state.mark_copied();
});
cx.write_to_clipboard(ClipboardItem::new_string(
copy_email.to_string(),
copy_sha.to_string(),
));
let state_id = copied_state.entity_id();
cx.spawn(async move |cx| {
@@ -2922,92 +3026,46 @@ impl GitGraph {
})
})
.detach();
}),
)
})
.child({
let copy_sha = full_sha.clone();
let copied_state: Entity<CopiedState> =
window.use_keyed_state("sha-copy", cx, CopiedState::new);
let is_copied = copied_state.read(cx).is_copied();
let (icon, icon_color, tooltip_label) = if is_copied {
(IconName::Check, Color::Success, "Commit SHA Copied!")
} else {
(IconName::Hash, Color::Muted, "Copy Commit SHA")
};
Button::new("sha-button", &full_sha)
.start_icon(
Icon::new(icon).size(IconSize::Small).color(icon_color),
)
.label_size(LabelSize::Small)
.truncate(true)
.color(Color::Muted)
.tooltip({
let full_sha = full_sha.clone();
move |_, cx| {
Tooltip::with_meta(
tooltip_label,
None,
full_sha.clone(),
cx,
)
}
})
.on_click(move |_, _, cx| {
copied_state.update(cx, |state, _cx| {
state.mark_copied();
});
cx.write_to_clipboard(ClipboardItem::new_string(
copy_sha.to_string(),
));
let state_id = copied_state.entity_id();
cx.spawn(async move |cx| {
cx.background_executor()
.timer(COPIED_STATE_DURATION)
.await;
cx.update(|cx| {
cx.notify(state_id);
})
})
.detach();
})
})
.when_some(remote.clone(), |this, remote| {
let provider_name = remote.host.name();
let icon = ui::git_hosting_provider_icon(provider_name.as_str());
let parsed_remote = ParsedGitRemote {
owner: remote.owner.as_ref().into(),
repo: remote.repo.as_ref().into(),
};
let params = BuildCommitPermalinkParams {
sha: full_sha.as_ref(),
};
let url = remote
.host
.build_commit_permalink(&parsed_remote, params)
.to_string();
})
.when_some(remote.clone(), |this, remote| {
let provider_name = remote.host.name();
let icon =
ui::git_hosting_provider_icon(provider_name.as_str());
let parsed_remote = ParsedGitRemote {
owner: remote.owner.as_ref().into(),
repo: remote.repo.as_ref().into(),
};
let params = BuildCommitPermalinkParams {
sha: full_sha.as_ref(),
};
let url = remote
.host
.build_commit_permalink(&parsed_remote, params)
.to_string();
this.child(
Button::new(
"view-on-provider",
format!("View on {}", provider_name),
this.child(
Button::new(
"view-on-provider",
format!("View on {}", provider_name),
)
.start_icon(
Icon::new(icon)
.size(IconSize::Small)
.color(Color::Muted),
)
.label_size(LabelSize::Small)
.truncate(true)
.color(Color::Muted)
.on_click(
move |_, _, cx| {
cx.open_url(&url);
},
),
)
.start_icon(
Icon::new(icon).size(IconSize::Small).color(Color::Muted),
)
.label_size(LabelSize::Small)
.truncate(true)
.color(Color::Muted)
.on_click(
move |_, _, cx| {
cx.open_url(&url);
},
),
)
}),
),
}),
)
}),
)
.child(Divider::horizontal())
.child(self.render_commit_message(window, cx))
@@ -3670,6 +3728,8 @@ impl GitGraph {
.base_text_style
.line_height_in_pixels(rem_size);
let collapsed = self.commit_details_message_collapsed;
div()
// Using grid over flexbox because the structure of this side
// panel prvents taffy from calculating a concrete width correctly,
@@ -3683,21 +3743,42 @@ impl GitGraph {
.grid_cols(1)
.gap_1()
.child(
div()
.relative()
h_flex()
.w_full()
.gap_1()
.child(
div()
.id("commit-message")
.text_sm()
.w_full()
.max_h(line_height * 12.)
.overflow_y_scroll()
.track_scroll(scroll_handle)
.child(MarkdownElement::new(message.clone(), message_style)),
Disclosure::new("toggle-commit-message", !collapsed).on_click(cx.listener(
|this, _, _, cx| {
this.commit_details_message_collapsed =
!this.commit_details_message_collapsed;
cx.notify();
},
)),
)
.vertical_scrollbar_for(scroll_handle, window, cx),
.child(
Label::new("Message")
.size(LabelSize::Small)
.color(Color::Muted),
),
)
.when(!collapsed, |this| {
this.child(
div()
.relative()
.w_full()
.child(
div()
.id("commit-message")
.text_sm()
.w_full()
.max_h(line_height * 12.)
.overflow_y_scroll()
.track_scroll(scroll_handle)
.child(MarkdownElement::new(message.clone(), message_style)),
)
.vertical_scrollbar_for(scroll_handle, window, cx),
)
})
.into_any_element()
}
}
+163 -32
View File
@@ -44,8 +44,8 @@ use git::{
};
use git::{
ExpandCommitEditor, GitHostingProviderRegistry, GitRemote, RestoreTrackedFiles, StageAll,
StashAll, StashApply, StashPop, StashStaged, StashTracked, ToggleFillCommitEditor,
TrashUntrackedFiles, UnstageAll, ViewFile, parse_git_remote_url,
StashAll, StashApply, StashPop, StashStaged, StashTracked, ToggleCommitEditor,
ToggleFillCommitEditor, TrashUntrackedFiles, UnstageAll, ViewFile, parse_git_remote_url,
};
use gpui::{
AbsoluteLength, Action, Anchor, AnyElement, AsyncApp, AsyncWindowContext, ClickEvent,
@@ -75,8 +75,8 @@ use prompt_store::RULES_FILE_NAMES;
use serde::{Deserialize, Serialize};
use settings::{
GitPanelClickBehavior, GitPanelGroupBy, GitPanelSortBy, Settings, SettingsStore, StatusStyle,
update_settings_file,
GitPanelClickBehavior, GitPanelCommitEditor, GitPanelGroupBy, GitPanelSortBy, Settings,
SettingsStore, StatusStyle, update_settings_file,
};
use smallvec::SmallVec;
use std::cell::Cell;
@@ -520,6 +520,13 @@ pub fn register(workspace: &mut Workspace) {
});
}
});
workspace.register_action(|workspace, _: &ToggleCommitEditor, window, cx| {
if let Some(panel) = workspace.panel::<GitPanel>(cx) {
panel.update(cx, |panel, cx| {
panel.toggle_commit_editor(&Default::default(), window, cx)
});
}
});
workspace.register_action(|workspace, _: &git::Init, window, cx| {
if let Some(panel) = workspace.panel::<GitPanel>(cx) {
panel.update(cx, |panel, cx| panel.git_init(window, cx));
@@ -545,6 +552,9 @@ struct SerializedGitPanel {
signoff_enabled: bool,
#[serde(default)]
commit_messages: BTreeMap<String, SerializedCommitMessage>,
/// `None` means the user never toggled it, so the setting decides.
#[serde(default)]
commit_editor_collapsed: Option<bool>,
}
#[derive(Clone, Default, Serialize, Deserialize)]
@@ -1115,6 +1125,11 @@ pub struct GitPanel {
pub(crate) commit_editor: Entity<Editor>,
/// Whether the commit editor should fill the vertical height of the panel.
commit_editor_expanded: bool,
/// Whether the commit editor is hidden, leaving only the commit button row.
commit_editor_collapsed: bool,
/// Set once the user toggles the editor here, so an untouched workspace keeps
/// following `git_panel.commit_editor` instead of pinning its first value.
commit_editor_toggled: bool,
conflicted_count: usize,
conflicted_staged_count: usize,
add_coauthors: bool,
@@ -1274,6 +1289,15 @@ impl GitPanel {
let signoff_enabled = serialized_panel
.as_ref()
.is_some_and(|panel| panel.signoff_enabled);
let commit_editor_was_serialized = serialized_panel
.as_ref()
.is_some_and(|panel| panel.commit_editor_collapsed.is_some());
let commit_editor_collapsed = serialized_panel
.as_ref()
.and_then(|panel| panel.commit_editor_collapsed)
.unwrap_or_else(|| {
GitPanelSettings::get_global(cx).commit_editor == GitPanelCommitEditor::Collapsed
});
let active_work_directory_abs_path = active_repository.as_ref().map(|repository| {
repository
.read(cx)
@@ -1313,6 +1337,7 @@ impl GitPanel {
let mut was_file_icons = GitPanelSettings::get_global(cx).file_icons;
let mut was_folder_indicator = GitPanelSettings::get_global(cx).folder_indicator;
let mut was_diff_stats = GitPanelSettings::get_global(cx).diff_stats;
let mut was_commit_editor = GitPanelSettings::get_global(cx).commit_editor;
cx.observe_global_in::<SettingsStore>(window, move |this, window, cx| {
let settings = GitPanelSettings::get_global(cx);
let sort_by = settings.sort_by;
@@ -1321,6 +1346,15 @@ impl GitPanel {
let file_icons = settings.file_icons;
let folder_indicator = settings.folder_indicator;
let diff_stats = settings.diff_stats;
let commit_editor = settings.commit_editor;
// Changing the setting is an explicit request, so it wins over
// whatever this workspace last persisted.
if commit_editor != was_commit_editor {
let collapsed = commit_editor == GitPanelCommitEditor::Collapsed;
if collapsed != this.commit_editor_collapsed {
this.toggle_commit_editor(&Default::default(), window, cx);
}
}
if tree_view != was_tree_view {
match (&mut this.view_mode, tree_view) {
(GitPanelViewMode::Tree(state), false) => {
@@ -1355,6 +1389,7 @@ impl GitPanel {
was_file_icons = file_icons;
was_folder_indicator = folder_indicator;
was_diff_stats = diff_stats;
was_commit_editor = commit_editor;
})
.detach();
@@ -1432,6 +1467,8 @@ impl GitPanel {
active_repository,
commit_editor,
commit_editor_expanded: false,
commit_editor_collapsed,
commit_editor_toggled: commit_editor_was_serialized,
conflicted_count: 0,
conflicted_staged_count: 0,
add_coauthors: true,
@@ -1912,6 +1949,9 @@ impl GitPanel {
fn serialize(&mut self, cx: &mut Context<Self>) {
let signoff_enabled = self.signoff_enabled;
let commit_editor_collapsed = self
.commit_editor_toggled
.then_some(self.commit_editor_collapsed);
let commit_messages = self.serialized_commit_messages(cx);
let kvp = KeyValueStore::global(cx);
@@ -1939,6 +1979,7 @@ impl GitPanel {
serde_json::to_string(&SerializedGitPanel {
signoff_enabled,
commit_messages,
commit_editor_collapsed,
})?,
)
.await?;
@@ -6516,6 +6557,23 @@ impl GitPanel {
cx.notify();
}
fn toggle_commit_editor(
&mut self,
_: &ToggleCommitEditor,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.commit_editor_collapsed = !self.commit_editor_collapsed;
self.commit_editor_toggled = true;
// Filling the panel and being hidden are mutually exclusive states, so
// collapsing has to undo the fill rather than leave it dangling.
if self.commit_editor_collapsed && self.commit_editor_expanded {
self.toggle_fill_commit_editor(&Default::default(), window, cx);
}
self.serialize(cx);
cx.notify();
}
fn expand_commit_editor(
&mut self,
_: &ExpandCommitEditor,
@@ -6793,6 +6851,25 @@ impl GitPanel {
}))
});
let collapsed = self.commit_editor_collapsed;
let toggle_commit_editor_button = {
let (icon, label) = if collapsed {
(IconName::ChevronUp, "Show Commit Editor")
} else {
(IconName::ChevronDown, "Hide Commit Editor")
};
let focus_handle = self.focus_handle.clone();
IconButton::new("toggle-commit-editor", icon)
.icon_size(IconSize::Small)
.tooltip(move |_window, cx| {
Tooltip::for_action_in(label, &git::ToggleCommitEditor, &focus_handle, cx)
})
.on_click(cx.listener(move |_, _, window, cx| {
window.dispatch_action(git::ToggleCommitEditor.boxed_clone(), cx)
}))
};
let footer = v_flex()
.when(self.commit_editor_expanded, |this| this.flex_1().min_h_0())
.child(PanelRepoFooter::new(
@@ -6834,32 +6911,34 @@ impl GitPanel {
} else {
cx.theme().colors().border
})
.on_click(cx.listener(move |this, _: &ClickEvent, window, cx| {
window.focus(&this.commit_editor.focus_handle(cx), cx);
}))
.child(
h_flex()
.size_full()
.child(
div()
.pt_2()
.px_2()
.h_full()
.flex_grow_1()
.cursor_text()
.on_action(|&zed_actions::editor::MoveUp, _, cx| {
cx.stop_propagation();
})
.on_action(|&zed_actions::editor::MoveDown, _, cx| {
cx.stop_propagation();
})
.child(EditorElement::new(
&self.commit_editor,
panel_editor_style,
)),
)
.child(vertical_buttons),
)
.when(!collapsed, |this| {
this.on_click(cx.listener(move |this, _: &ClickEvent, window, cx| {
window.focus(&this.commit_editor.focus_handle(cx), cx);
}))
.child(
h_flex()
.size_full()
.child(
div()
.pt_2()
.px_2()
.h_full()
.flex_grow_1()
.cursor_text()
.on_action(|&zed_actions::editor::MoveUp, _, cx| {
cx.stop_propagation();
})
.on_action(|&zed_actions::editor::MoveDown, _, cx| {
cx.stop_propagation();
})
.child(EditorElement::new(
&self.commit_editor,
panel_editor_style,
)),
)
.child(vertical_buttons),
)
})
.child(
h_flex()
.id("commit-footer")
@@ -6871,8 +6950,10 @@ impl GitPanel {
})
.justify_between()
.child(
self.render_generate_commit_message_button(cx)
.unwrap_or_else(|| div().into_any_element()),
h_flex()
.gap_0p5()
.child(toggle_commit_editor_button)
.children(self.render_generate_commit_message_button(cx)),
)
.child(
h_flex()
@@ -9300,6 +9381,7 @@ impl Render for GitPanel {
.on_action(cx.listener(Self::focus_changes_list))
.on_action(cx.listener(Self::focus_editor))
.on_action(cx.listener(Self::expand_commit_editor))
.on_action(cx.listener(Self::toggle_commit_editor))
.when(has_write_access && has_co_authors, |git_panel| {
git_panel.on_action(cx.listener(Self::toggle_fill_co_authors))
})
@@ -9403,6 +9485,7 @@ impl editor::Addon for GitPanelAddon {
impl Panel for GitPanel {
fn activation_focus_handle(&self, cx: &App) -> FocusHandle {
if self.active_tab == GitPanelTab::Changes
&& !self.commit_editor_collapsed
&& (self.entries.is_empty() || self.commit_editor_expanded)
{
self.commit_editor.focus_handle(cx)
@@ -12662,6 +12745,7 @@ mod tests {
SerializedGitPanel {
signoff_enabled: false,
commit_messages: panel.serialized_commit_messages(cx),
commit_editor_collapsed: None,
}
});
@@ -12705,6 +12789,7 @@ mod tests {
let mismatched_serialized_panel = SerializedGitPanel {
signoff_enabled: false,
commit_editor_collapsed: None,
commit_messages: BTreeMap::from_iter([(
path!("/root/other-project").to_string(),
SerializedCommitMessage {
@@ -12803,6 +12888,7 @@ mod tests {
let serialized_panel = panel.update(cx, |panel, cx| SerializedGitPanel {
signoff_enabled: false,
commit_messages: panel.serialized_commit_messages(cx),
commit_editor_collapsed: None,
});
let buffer = repository.read_with(cx, |repository, _| {
repository.commit_message_buffer().unwrap().clone()
@@ -12898,6 +12984,7 @@ mod tests {
let serialized_panel = panel.update(cx, |panel, cx| SerializedGitPanel {
signoff_enabled: false,
commit_messages: panel.serialized_commit_messages(cx),
commit_editor_collapsed: None,
});
// Simulate a restart and restore from the serialized state.
@@ -14369,6 +14456,50 @@ mod tests {
});
}
#[gpui::test]
async fn test_toggle_commit_editor_collapsed(cx: &mut TestAppContext) {
init_test(cx);
let fs = FakeFs::new(cx.background_executor.clone());
fs.insert_tree(
"/root",
json!({ "project": { ".git": {}, "src": { "main.rs": "fn main() {}" } } }),
)
.await;
let project = Project::test(fs.clone(), [Path::new(path!("/root/project"))], cx).await;
let window_handle =
cx.add_window(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));
let workspace = window_handle
.read_with(cx, |mw, _| mw.workspace().clone())
.unwrap();
let cx = &mut VisualTestContext::from_window(window_handle.into(), cx);
cx.executor().run_until_parked();
let panel = workspace.update_in(cx, GitPanel::new);
panel.update_in(cx, |panel, window, cx| {
assert!(!panel.commit_editor_collapsed);
panel.toggle_commit_editor(&ToggleCommitEditor, window, cx);
assert!(panel.commit_editor_collapsed);
panel.toggle_commit_editor(&ToggleCommitEditor, window, cx);
assert!(!panel.commit_editor_collapsed);
panel.toggle_fill_commit_editor(&ToggleFillCommitEditor, window, cx);
assert!(panel.commit_editor_expanded);
// Collapsing has to undo the fill, the two states can't both hold.
panel.toggle_commit_editor(&ToggleCommitEditor, window, cx);
assert!(panel.commit_editor_collapsed);
assert!(!panel.commit_editor_expanded);
assert!(matches!(
panel.commit_editor.read(cx).mode().clone(),
EditorMode::AutoHeight { .. }
));
});
}
#[gpui::test]
async fn test_focus_handle(cx: &mut TestAppContext) {
init_test(cx);
+4 -2
View File
@@ -3,8 +3,8 @@ use gpui::Pixels;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{
FolderIndicator, GitPanelClickBehavior, GitPanelGroupBy, GitPanelSortBy, IntoGpui,
RegisterSetting, Settings, StatusStyle,
FolderIndicator, GitPanelClickBehavior, GitPanelCommitEditor, GitPanelGroupBy, GitPanelSortBy,
IntoGpui, RegisterSetting, Settings, StatusStyle,
};
use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar};
use workspace::dock::DockPosition;
@@ -33,6 +33,7 @@ pub struct GitPanelSettings {
pub starts_open: bool,
pub commit_title_max_length: usize,
pub entry_primary_click_action: GitPanelClickBehavior,
pub commit_editor: GitPanelCommitEditor,
}
#[derive(Default)]
@@ -82,6 +83,7 @@ impl Settings for GitPanelSettings {
starts_open: git_panel.starts_open.unwrap(),
commit_title_max_length: git_panel.commit_title_max_length.unwrap(),
entry_primary_click_action: git_panel.entry_primary_click_action.unwrap(),
commit_editor: git_panel.commit_editor.unwrap(),
}
}
}
@@ -813,6 +813,34 @@ pub struct GitPanelSettingsContent {
///
/// Default: project_diff
pub entry_primary_click_action: Option<GitPanelClickBehavior>,
/// Whether the commit message editor is shown in the Git panel by default.
///
/// Default: expanded
pub commit_editor: Option<GitPanelCommitEditor>,
}
#[derive(
Copy,
Clone,
Debug,
Default,
Serialize,
Deserialize,
JsonSchema,
MergeFrom,
PartialEq,
Eq,
strum::VariantArray,
strum::VariantNames,
)]
#[serde(rename_all = "snake_case")]
pub enum GitPanelCommitEditor {
/// Show the commit message editor.
#[default]
Expanded,
/// Hide the commit message editor, leaving only the commit button row.
Collapsed,
}
#[derive(
+20 -1
View File
@@ -6440,7 +6440,7 @@ fn panels_page() -> SettingsPage {
]
}
fn git_panel_section() -> [SettingsPageItem; 18] {
fn git_panel_section() -> [SettingsPageItem; 19] {
[
SettingsPageItem::SectionHeader("Git Panel"),
SettingsPageItem::SettingItem(SettingItem {
@@ -6702,6 +6702,25 @@ fn panels_page() -> SettingsPage {
metadata: None,
files: USER,
}),
SettingsPageItem::SettingItem(SettingItem {
title: "Commit Editor",
description: "Whether the commit message editor is shown in the Git panel by default.",
field: Box::new(SettingField {
organization_override: None,
json_path: Some("git_panel.commit_editor"),
pick: |settings_content| {
settings_content.git_panel.as_ref()?.commit_editor.as_ref()
},
write: |settings_content, value, _| {
settings_content
.git_panel
.get_or_insert_default()
.commit_editor = value;
},
}),
metadata: None,
files: USER,
}),
SettingsPageItem::SettingItem(SettingItem {
title: "Show Count Badge",
description: "Whether to show a badge on the git panel icon with the count of uncommitted changes.",
+1
View File
@@ -644,6 +644,7 @@ fn init_renderers(cx: &mut App) {
.add_basic_renderer::<settings::GitPanelClickBehavior>(render_dropdown)
.add_basic_renderer::<settings::GitPanelSortBy>(render_dropdown)
.add_basic_renderer::<settings::GitPanelGroupBy>(render_dropdown)
.add_basic_renderer::<settings::GitPanelCommitEditor>(render_dropdown)
.add_basic_renderer::<settings::EncodingDisplayOptions>(render_dropdown)
.add_basic_renderer::<settings::PaneSplitDirectionHorizontal>(render_dropdown)
.add_basic_renderer::<settings::PaneSplitDirectionVertical>(render_dropdown)
+1
View File
@@ -6124,6 +6124,7 @@ See the [debugger page](../debugger.md) for more information about debugging sup
- `tree_view`: Whether to show entries in tree or flat view in the panel
- `scrollbar`: When to show the scrollbar in the git panel
- `starts_open`: Whether the git panel should open on startup
- `commit_editor`: Whether the commit message editor is shown in the git panel by default. Can be `expanded` or `collapsed`
- `show_count_badge`: Whether to show a badge on the git panel icon with the count of uncommitted changes
- `diff_stats`: Whether to show the addition/deletion change count next to each file in the git panel
- `commit_title_max_length`: Maximum length of the commit message title before a warning is shown. Set to `0` to disable