Disable restore hunk control for created files (#25841)
Release Notes: - Git Beta: disable hunk restore action and button for created files
This commit is contained in:
parent
efaf358876
commit
a88af7351a
3 changed files with 17 additions and 1 deletions
|
@ -261,6 +261,7 @@ enum DisplayDiffHunk {
|
|||
display_row: DisplayRow,
|
||||
},
|
||||
Unfolded {
|
||||
is_created_file: bool,
|
||||
diff_base_byte_range: Range<usize>,
|
||||
display_row_range: Range<DisplayRow>,
|
||||
multi_buffer_range: Range<Anchor>,
|
||||
|
@ -7895,6 +7896,9 @@ impl Editor {
|
|||
hunk: &MultiBufferDiffHunk,
|
||||
cx: &mut App,
|
||||
) -> Option<()> {
|
||||
if hunk.is_created_file() {
|
||||
return None;
|
||||
}
|
||||
let buffer = self.buffer.read(cx);
|
||||
let diff = buffer.diff_for(hunk.buffer_id)?;
|
||||
let buffer = buffer.buffer(hunk.buffer_id)?;
|
||||
|
@ -17282,6 +17286,7 @@ impl EditorSnapshot {
|
|||
if hunk_display_end.column() > 0 {
|
||||
end_row.0 += 1;
|
||||
}
|
||||
let is_created_file = hunk.is_created_file();
|
||||
DisplayDiffHunk::Unfolded {
|
||||
status: hunk.status(),
|
||||
diff_base_byte_range: hunk.diff_base_byte_range,
|
||||
|
@ -17291,6 +17296,7 @@ impl EditorSnapshot {
|
|||
hunk.buffer_id,
|
||||
hunk.buffer_range,
|
||||
),
|
||||
is_created_file,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -3948,6 +3948,7 @@ impl EditorElement {
|
|||
display_row_range,
|
||||
multi_buffer_range,
|
||||
status,
|
||||
is_created_file,
|
||||
..
|
||||
} = &hunk
|
||||
{
|
||||
|
@ -3979,6 +3980,7 @@ impl EditorElement {
|
|||
display_row_range.start.0,
|
||||
status,
|
||||
multi_buffer_range.clone(),
|
||||
*is_created_file,
|
||||
line_height,
|
||||
&editor,
|
||||
cx,
|
||||
|
@ -8786,6 +8788,7 @@ fn diff_hunk_controls(
|
|||
row: u32,
|
||||
status: &DiffHunkStatus,
|
||||
hunk_range: Range<Anchor>,
|
||||
is_created_file: bool,
|
||||
line_height: Pixels,
|
||||
editor: &Entity<Editor>,
|
||||
cx: &mut App,
|
||||
|
@ -8801,6 +8804,7 @@ fn diff_hunk_controls(
|
|||
.rounded_b_lg()
|
||||
.bg(cx.theme().colors().editor_background)
|
||||
.gap_1()
|
||||
.occlude()
|
||||
.child(if status.has_secondary_hunk() {
|
||||
Button::new(("stage", row as u64), "Stage")
|
||||
.alpha(if status.is_pending() { 0.66 } else { 1.0 })
|
||||
|
@ -8879,7 +8883,8 @@ fn diff_hunk_controls(
|
|||
editor.restore_hunks_in_ranges(vec![point..point], window, cx);
|
||||
});
|
||||
}
|
||||
}),
|
||||
})
|
||||
.disabled(is_created_file),
|
||||
)
|
||||
.when(
|
||||
!editor.read(cx).buffer().read(cx).all_diff_hunks_expanded(),
|
||||
|
|
|
@ -154,6 +154,11 @@ impl MultiBufferDiffHunk {
|
|||
secondary: self.secondary_status,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_created_file(&self) -> bool {
|
||||
self.diff_base_byte_range == (0..0)
|
||||
&& self.buffer_range == (text::Anchor::MIN..text::Anchor::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Hash, Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue