Skip to content

Commit 05d0621

Browse files
committed
Redundant code
1 parent 0248782 commit 05d0621

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

crates/git_ui/src/worktree_picker.rs

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -111,36 +111,9 @@ impl WorktreeList {
111111
.update(cx, |picker, _| picker.delegate.modifiers = ev.modifiers)
112112
}
113113

114-
fn handle_worktree_from_default_on_window(
114+
fn handle_new_worktree(
115115
&mut self,
116-
_: &WorktreeFromDefaultOnWindow,
117-
window: &mut Window,
118-
cx: &mut Context<Self>,
119-
) {
120-
self.picker.update(cx, |picker, cx| {
121-
let ix = picker.delegate.selected_index();
122-
let Some(entry) = picker.delegate.matches.get(ix) else {
123-
return;
124-
};
125-
let Some(default_branch) = picker.delegate.default_branch.clone() else {
126-
return;
127-
};
128-
if !entry.is_new {
129-
return;
130-
}
131-
picker.delegate.create_worktree(
132-
entry.worktree.name(),
133-
true,
134-
Some(default_branch.into()),
135-
window,
136-
cx,
137-
);
138-
})
139-
}
140-
141-
fn handle_worktree_from_default(
142-
&mut self,
143-
_: &WorktreeFromDefault,
116+
replace_current_window: bool,
144117
window: &mut Window,
145118
cx: &mut Context<Self>,
146119
) {
@@ -157,7 +130,7 @@ impl WorktreeList {
157130
}
158131
picker.delegate.create_worktree(
159132
entry.worktree.name(),
160-
false,
133+
replace_current_window,
161134
Some(default_branch.into()),
162135
window,
163136
cx,
@@ -180,8 +153,12 @@ impl Render for WorktreeList {
180153
.key_context("GitWorktreeSelector")
181154
.w(self.width)
182155
.on_modifiers_changed(cx.listener(Self::handle_modifiers_changed))
183-
.on_action(cx.listener(Self::handle_worktree_from_default))
184-
.on_action(cx.listener(Self::handle_worktree_from_default_on_window))
156+
.on_action(cx.listener(|this, _: &WorktreeFromDefault, w, cx| {
157+
this.handle_new_worktree(false, w, cx)
158+
}))
159+
.on_action(cx.listener(|this, _: &WorktreeFromDefaultOnWindow, w, cx| {
160+
this.handle_new_worktree(true, w, cx)
161+
}))
185162
.child(self.picker.clone())
186163
.on_mouse_down_out({
187164
cx.listener(move |this, _, window, cx| {
@@ -431,10 +408,8 @@ impl PickerDelegate for WorktreeListDelegate {
431408
return;
432409
};
433410
if entry.is_new {
434-
// We handle worktree creation logic
435411
self.create_worktree(&entry.worktree.name(), secondary, None, window, cx);
436412
} else {
437-
// If secondary click, we open on a new window
438413
self.open_worktree(&entry.worktree.path, secondary, window, cx);
439414
}
440415

0 commit comments

Comments
 (0)