chore: Update BranchListDelegate to use WeakView<Workspace> (#20157)
This commit is contained in:
parent
67be6ec3b5
commit
20eeb78251
1 changed files with 11 additions and 5 deletions
|
@ -1,10 +1,11 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use git::repository::Branch;
|
use git::repository::Branch;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, rems, AnyElement, AppContext, AsyncAppContext, DismissEvent, EventEmitter,
|
actions, rems, AnyElement, AppContext, AsyncAppContext, DismissEvent, EventEmitter,
|
||||||
FocusHandle, FocusableView, InteractiveElement, IntoElement, ParentElement, Render,
|
FocusHandle, FocusableView, InteractiveElement, IntoElement, ParentElement, Render,
|
||||||
SharedString, Styled, Subscription, Task, View, ViewContext, VisualContext, WindowContext,
|
SharedString, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
|
||||||
|
WindowContext,
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use project::ProjectPath;
|
use project::ProjectPath;
|
||||||
|
@ -95,7 +96,7 @@ impl BranchEntry {
|
||||||
pub struct BranchListDelegate {
|
pub struct BranchListDelegate {
|
||||||
matches: Vec<BranchEntry>,
|
matches: Vec<BranchEntry>,
|
||||||
all_branches: Vec<Branch>,
|
all_branches: Vec<Branch>,
|
||||||
workspace: View<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
selected_index: usize,
|
selected_index: usize,
|
||||||
last_query: String,
|
last_query: String,
|
||||||
/// Max length of branch name before we truncate it and add a trailing `...`.
|
/// Max length of branch name before we truncate it and add a trailing `...`.
|
||||||
|
@ -122,7 +123,7 @@ impl BranchListDelegate {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
matches: vec![],
|
matches: vec![],
|
||||||
workspace,
|
workspace: workspace.downgrade(),
|
||||||
all_branches,
|
all_branches,
|
||||||
selected_index: 0,
|
selected_index: 0,
|
||||||
last_query: Default::default(),
|
last_query: Default::default(),
|
||||||
|
@ -235,8 +236,13 @@ impl PickerDelegate for BranchListDelegate {
|
||||||
let branch = branch.clone();
|
let branch = branch.clone();
|
||||||
|picker, mut cx| async move {
|
|picker, mut cx| async move {
|
||||||
let branch_change_task = picker.update(&mut cx, |this, cx| {
|
let branch_change_task = picker.update(&mut cx, |this, cx| {
|
||||||
let project = this.delegate.workspace.read(cx).project().read(cx);
|
let workspace = this
|
||||||
|
.delegate
|
||||||
|
.workspace
|
||||||
|
.upgrade()
|
||||||
|
.ok_or_else(|| anyhow!("workspace was dropped"))?;
|
||||||
|
|
||||||
|
let project = workspace.read(cx).project().read(cx);
|
||||||
let branch_to_checkout = match branch {
|
let branch_to_checkout = match branch {
|
||||||
BranchEntry::Branch(branch) => branch.string,
|
BranchEntry::Branch(branch) => branch.string,
|
||||||
BranchEntry::NewBranch { name: branch_name } => branch_name,
|
BranchEntry::NewBranch { name: branch_name } => branch_name,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue