git_ui.rs

  1use std::any::Any;
  2
  3use ::settings::Settings;
  4use command_palette_hooks::CommandPaletteFilter;
  5use commit_modal::CommitModal;
  6use editor::{Editor, EditorElement, EditorStyle, actions::DiffClipboardWithSelectionData};
  7use ui::{
  8    Headline, HeadlineSize, Icon, IconName, IconSize, IntoElement, ParentElement, Render, Styled,
  9    StyledExt, div, h_flex, rems, v_flex,
 10};
 11
 12mod blame_ui;
 13
 14use git::{
 15    repository::{Branch, Upstream, UpstreamTracking, UpstreamTrackingStatus},
 16    status::{FileStatus, StatusCode, UnmergedStatus, UnmergedStatusCode},
 17};
 18use git_panel_settings::GitPanelSettings;
 19use gpui::{
 20    Action, App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, SharedString,
 21    TextStyle, Window, actions,
 22};
 23use menu::{Cancel, Confirm};
 24use onboarding::GitOnboardingModal;
 25use project::git_store::Repository;
 26use project_diff::ProjectDiff;
 27use theme::ThemeSettings;
 28use ui::prelude::*;
 29use workspace::{ModalView, Workspace, notifications::DetachAndPromptErr};
 30use zed_actions;
 31
 32use crate::{git_panel::GitPanel, text_diff_view::TextDiffView};
 33
 34mod askpass_modal;
 35pub mod branch_picker;
 36mod commit_modal;
 37pub mod commit_tooltip;
 38mod commit_view;
 39mod conflict_view;
 40pub mod file_diff_view;
 41pub mod git_panel;
 42mod git_panel_settings;
 43pub mod onboarding;
 44pub mod picker_prompt;
 45pub mod project_diff;
 46pub(crate) mod remote_output;
 47pub mod repository_selector;
 48pub mod text_diff_view;
 49
 50actions!(
 51    git,
 52    [
 53        /// Resets the git onboarding state to show the tutorial again.
 54        ResetOnboarding
 55    ]
 56);
 57
 58pub fn init(cx: &mut App) {
 59    GitPanelSettings::register(cx);
 60
 61    editor::set_blame_renderer(blame_ui::GitBlameRenderer, cx);
 62
 63    cx.observe_new(|editor: &mut Editor, _, cx| {
 64        conflict_view::register_editor(editor, editor.buffer().clone(), cx);
 65    })
 66    .detach();
 67
 68    cx.observe_new(|workspace: &mut Workspace, _, cx| {
 69        ProjectDiff::register(workspace, cx);
 70        CommitModal::register(workspace);
 71        git_panel::register(workspace);
 72        repository_selector::register(workspace);
 73        branch_picker::register(workspace);
 74
 75        let project = workspace.project().read(cx);
 76        if project.is_read_only(cx) {
 77            return;
 78        }
 79        if !project.is_via_collab() {
 80            workspace.register_action(|workspace, _: &git::Fetch, window, cx| {
 81                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
 82                    return;
 83                };
 84                panel.update(cx, |panel, cx| {
 85                    panel.fetch(true, window, cx);
 86                });
 87            });
 88            workspace.register_action(|workspace, _: &git::FetchFrom, window, cx| {
 89                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
 90                    return;
 91                };
 92                panel.update(cx, |panel, cx| {
 93                    panel.fetch(false, window, cx);
 94                });
 95            });
 96            workspace.register_action(|workspace, _: &git::Push, window, cx| {
 97                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
 98                    return;
 99                };
100                panel.update(cx, |panel, cx| {
101                    panel.push(false, false, window, cx);
102                });
103            });
104            workspace.register_action(|workspace, _: &git::PushTo, window, cx| {
105                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
106                    return;
107                };
108                panel.update(cx, |panel, cx| {
109                    panel.push(false, true, window, cx);
110                });
111            });
112            workspace.register_action(|workspace, _: &git::ForcePush, window, cx| {
113                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
114                    return;
115                };
116                panel.update(cx, |panel, cx| {
117                    panel.push(true, false, window, cx);
118                });
119            });
120            workspace.register_action(|workspace, _: &git::Pull, window, cx| {
121                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
122                    return;
123                };
124                panel.update(cx, |panel, cx| {
125                    panel.pull(window, cx);
126                });
127            });
128        }
129        workspace.register_action(|workspace, action: &git::StashAll, window, cx| {
130            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
131                return;
132            };
133            panel.update(cx, |panel, cx| {
134                panel.stash_all(action, window, cx);
135            });
136        });
137        workspace.register_action(|workspace, action: &git::StashPop, window, cx| {
138            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
139                return;
140            };
141            panel.update(cx, |panel, cx| {
142                panel.stash_pop(action, window, cx);
143            });
144        });
145        workspace.register_action(|workspace, action: &git::StageAll, window, cx| {
146            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
147                return;
148            };
149            panel.update(cx, |panel, cx| {
150                panel.stage_all(action, window, cx);
151            });
152        });
153        workspace.register_action(|workspace, action: &git::UnstageAll, window, cx| {
154            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
155                return;
156            };
157            panel.update(cx, |panel, cx| {
158                panel.unstage_all(action, window, cx);
159            });
160        });
161        CommandPaletteFilter::update_global(cx, |filter, _cx| {
162            filter.hide_action_types(&[
163                zed_actions::OpenGitIntegrationOnboarding.type_id(),
164                // ResetOnboarding.type_id(),
165            ]);
166        });
167        workspace.register_action(
168            move |workspace, _: &zed_actions::OpenGitIntegrationOnboarding, window, cx| {
169                GitOnboardingModal::toggle(workspace, window, cx)
170            },
171        );
172        workspace.register_action(move |_, _: &ResetOnboarding, window, cx| {
173            window.dispatch_action(workspace::RestoreBanner.boxed_clone(), cx);
174            window.refresh();
175        });
176        workspace.register_action(|workspace, _action: &git::Init, window, cx| {
177            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
178                return;
179            };
180            panel.update(cx, |panel, cx| {
181                panel.git_init(window, cx);
182            });
183        });
184        workspace.register_action(|workspace, _action: &git::Clone, window, cx| {
185            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
186                return;
187            };
188
189            workspace.toggle_modal(window, cx, |window, cx| {
190                GitCloneModal::show(panel, window, cx)
191            });
192        });
193        workspace.register_action(|workspace, _: &git::OpenModifiedFiles, window, cx| {
194            open_modified_files(workspace, window, cx);
195        });
196        workspace.register_action(|workspace, _: &git::RenameBranch, window, cx| {
197            rename_current_branch(workspace, window, cx);
198        });
199        workspace.register_action(
200            |workspace, action: &DiffClipboardWithSelectionData, window, cx| {
201                if let Some(task) = TextDiffView::open(action, workspace, window, cx) {
202                    task.detach();
203                };
204            },
205        );
206    })
207    .detach();
208}
209
210fn open_modified_files(
211    workspace: &mut Workspace,
212    window: &mut Window,
213    cx: &mut Context<Workspace>,
214) {
215    let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
216        return;
217    };
218    let modified_paths: Vec<_> = panel.update(cx, |panel, cx| {
219        let Some(repo) = panel.active_repository.as_ref() else {
220            return Vec::new();
221        };
222        let repo = repo.read(cx);
223        repo.cached_status()
224            .filter_map(|entry| {
225                if entry.status.is_modified() {
226                    repo.repo_path_to_project_path(&entry.repo_path, cx)
227                } else {
228                    None
229                }
230            })
231            .collect()
232    });
233    for path in modified_paths {
234        workspace.open_path(path, None, true, window, cx).detach();
235    }
236}
237
238pub fn git_status_icon(status: FileStatus) -> impl IntoElement {
239    GitStatusIcon::new(status)
240}
241
242struct RenameBranchModal {
243    current_branch: SharedString,
244    editor: Entity<Editor>,
245    repo: Entity<Repository>,
246}
247
248impl RenameBranchModal {
249    fn new(
250        current_branch: String,
251        repo: Entity<Repository>,
252        window: &mut Window,
253        cx: &mut Context<Self>,
254    ) -> Self {
255        let editor = cx.new(|cx| {
256            let mut editor = Editor::single_line(window, cx);
257            editor.set_text(current_branch.clone(), window, cx);
258            editor
259        });
260        Self {
261            current_branch: current_branch.into(),
262            editor,
263            repo,
264        }
265    }
266
267    fn cancel(&mut self, _: &Cancel, _window: &mut Window, cx: &mut Context<Self>) {
268        cx.emit(DismissEvent);
269    }
270
271    fn confirm(&mut self, _: &Confirm, window: &mut Window, cx: &mut Context<Self>) {
272        let new_name = self.editor.read(cx).text(cx);
273        if new_name.is_empty() || new_name == self.current_branch.as_ref() {
274            cx.emit(DismissEvent);
275            return;
276        }
277
278        let repo = self.repo.clone();
279        let current_branch = self.current_branch.to_string();
280        cx.spawn(async move |_, cx| {
281            match repo
282                .update(cx, |repo, _| {
283                    repo.rename_branch(current_branch, new_name.clone())
284                })?
285                .await
286            {
287                Ok(Ok(_)) => Ok(()),
288                Ok(Err(error)) => Err(error),
289                Err(_) => Err(anyhow::anyhow!("Operation was canceled")),
290            }
291        })
292        .detach_and_prompt_err("Failed to rename branch", window, cx, |_, _, _| None);
293        cx.emit(DismissEvent);
294    }
295}
296
297impl EventEmitter<DismissEvent> for RenameBranchModal {}
298impl ModalView for RenameBranchModal {}
299impl Focusable for RenameBranchModal {
300    fn focus_handle(&self, cx: &App) -> FocusHandle {
301        self.editor.focus_handle(cx)
302    }
303}
304
305impl Render for RenameBranchModal {
306    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
307        v_flex()
308            .key_context("RenameBranchModal")
309            .on_action(cx.listener(Self::cancel))
310            .on_action(cx.listener(Self::confirm))
311            .elevation_2(cx)
312            .w(rems(34.))
313            .child(
314                h_flex()
315                    .px_3()
316                    .pt_2()
317                    .pb_1()
318                    .w_full()
319                    .gap_1p5()
320                    .child(Icon::new(IconName::GitBranch).size(IconSize::XSmall))
321                    .child(
322                        Headline::new(format!("Rename Branch ({})", self.current_branch))
323                            .size(HeadlineSize::XSmall),
324                    ),
325            )
326            .child(div().px_3().pb_3().w_full().child(self.editor.clone()))
327    }
328}
329
330fn rename_current_branch(
331    workspace: &mut Workspace,
332    window: &mut Window,
333    cx: &mut Context<Workspace>,
334) {
335    let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
336        return;
337    };
338    let current_branch: Option<String> = panel.update(cx, |panel, cx| {
339        let repo = panel.active_repository.as_ref()?;
340        let repo = repo.read(cx);
341        repo.branch.as_ref().map(|branch| branch.name().to_string())
342    });
343
344    let Some(current_branch_name) = current_branch else {
345        return;
346    };
347
348    let repo = panel.read(cx).active_repository.clone();
349    let Some(repo) = repo else {
350        return;
351    };
352
353    workspace.toggle_modal(window, cx, |window, cx| {
354        RenameBranchModal::new(current_branch_name, repo, window, cx)
355    });
356}
357
358fn render_remote_button(
359    id: impl Into<SharedString>,
360    branch: &Branch,
361    keybinding_target: Option<FocusHandle>,
362    show_fetch_button: bool,
363) -> Option<impl IntoElement> {
364    let id = id.into();
365    let upstream = branch.upstream.as_ref();
366    match upstream {
367        Some(Upstream {
368            tracking: UpstreamTracking::Tracked(UpstreamTrackingStatus { ahead, behind }),
369            ..
370        }) => match (*ahead, *behind) {
371            (0, 0) if show_fetch_button => {
372                Some(remote_button::render_fetch_button(keybinding_target, id))
373            }
374            (0, 0) => None,
375            (ahead, 0) => Some(remote_button::render_push_button(
376                keybinding_target.clone(),
377                id,
378                ahead,
379            )),
380            (ahead, behind) => Some(remote_button::render_pull_button(
381                keybinding_target.clone(),
382                id,
383                ahead,
384                behind,
385            )),
386        },
387        Some(Upstream {
388            tracking: UpstreamTracking::Gone,
389            ..
390        }) => Some(remote_button::render_republish_button(
391            keybinding_target,
392            id,
393        )),
394        None => Some(remote_button::render_publish_button(keybinding_target, id)),
395    }
396}
397
398mod remote_button {
399    use gpui::{Action, AnyView, ClickEvent, Corner, FocusHandle};
400    use ui::{
401        App, ButtonCommon, Clickable, ContextMenu, ElementId, FluentBuilder, Icon, IconName,
402        IconSize, IntoElement, Label, LabelCommon, LabelSize, LineHeightStyle, ParentElement,
403        PopoverMenu, SharedString, SplitButton, Styled, Tooltip, Window, div, h_flex, rems,
404    };
405
406    pub fn render_fetch_button(
407        keybinding_target: Option<FocusHandle>,
408        id: SharedString,
409    ) -> SplitButton {
410        split_button(
411            id,
412            "Fetch",
413            0,
414            0,
415            Some(IconName::ArrowCircle),
416            keybinding_target.clone(),
417            move |_, window, cx| {
418                window.dispatch_action(Box::new(git::Fetch), cx);
419            },
420            move |window, cx| {
421                git_action_tooltip(
422                    "Fetch updates from remote",
423                    &git::Fetch,
424                    "git fetch",
425                    keybinding_target.clone(),
426                    window,
427                    cx,
428                )
429            },
430        )
431    }
432
433    pub fn render_push_button(
434        keybinding_target: Option<FocusHandle>,
435        id: SharedString,
436        ahead: u32,
437    ) -> SplitButton {
438        split_button(
439            id,
440            "Push",
441            ahead as usize,
442            0,
443            None,
444            keybinding_target.clone(),
445            move |_, window, cx| {
446                window.dispatch_action(Box::new(git::Push), cx);
447            },
448            move |window, cx| {
449                git_action_tooltip(
450                    "Push committed changes to remote",
451                    &git::Push,
452                    "git push",
453                    keybinding_target.clone(),
454                    window,
455                    cx,
456                )
457            },
458        )
459    }
460
461    pub fn render_pull_button(
462        keybinding_target: Option<FocusHandle>,
463        id: SharedString,
464        ahead: u32,
465        behind: u32,
466    ) -> SplitButton {
467        split_button(
468            id,
469            "Pull",
470            ahead as usize,
471            behind as usize,
472            None,
473            keybinding_target.clone(),
474            move |_, window, cx| {
475                window.dispatch_action(Box::new(git::Pull), cx);
476            },
477            move |window, cx| {
478                git_action_tooltip(
479                    "Pull",
480                    &git::Pull,
481                    "git pull",
482                    keybinding_target.clone(),
483                    window,
484                    cx,
485                )
486            },
487        )
488    }
489
490    pub fn render_publish_button(
491        keybinding_target: Option<FocusHandle>,
492        id: SharedString,
493    ) -> SplitButton {
494        split_button(
495            id,
496            "Publish",
497            0,
498            0,
499            Some(IconName::ExpandUp),
500            keybinding_target.clone(),
501            move |_, window, cx| {
502                window.dispatch_action(Box::new(git::Push), cx);
503            },
504            move |window, cx| {
505                git_action_tooltip(
506                    "Publish branch to remote",
507                    &git::Push,
508                    "git push --set-upstream",
509                    keybinding_target.clone(),
510                    window,
511                    cx,
512                )
513            },
514        )
515    }
516
517    pub fn render_republish_button(
518        keybinding_target: Option<FocusHandle>,
519        id: SharedString,
520    ) -> SplitButton {
521        split_button(
522            id,
523            "Republish",
524            0,
525            0,
526            Some(IconName::ExpandUp),
527            keybinding_target.clone(),
528            move |_, window, cx| {
529                window.dispatch_action(Box::new(git::Push), cx);
530            },
531            move |window, cx| {
532                git_action_tooltip(
533                    "Re-publish branch to remote",
534                    &git::Push,
535                    "git push --set-upstream",
536                    keybinding_target.clone(),
537                    window,
538                    cx,
539                )
540            },
541        )
542    }
543
544    fn git_action_tooltip(
545        label: impl Into<SharedString>,
546        action: &dyn Action,
547        command: impl Into<SharedString>,
548        focus_handle: Option<FocusHandle>,
549        window: &mut Window,
550        cx: &mut App,
551    ) -> AnyView {
552        let label = label.into();
553        let command = command.into();
554
555        if let Some(handle) = focus_handle {
556            Tooltip::with_meta_in(
557                label.clone(),
558                Some(action),
559                command.clone(),
560                &handle,
561                window,
562                cx,
563            )
564        } else {
565            Tooltip::with_meta(label.clone(), Some(action), command.clone(), window, cx)
566        }
567    }
568
569    fn render_git_action_menu(
570        id: impl Into<ElementId>,
571        keybinding_target: Option<FocusHandle>,
572    ) -> impl IntoElement {
573        PopoverMenu::new(id.into())
574            .trigger(
575                ui::ButtonLike::new_rounded_right("split-button-right")
576                    .layer(ui::ElevationIndex::ModalSurface)
577                    .size(ui::ButtonSize::None)
578                    .child(
579                        div()
580                            .px_1()
581                            .child(Icon::new(IconName::ChevronDown).size(IconSize::XSmall)),
582                    ),
583            )
584            .menu(move |window, cx| {
585                Some(ContextMenu::build(window, cx, |context_menu, _, _| {
586                    context_menu
587                        .when_some(keybinding_target.clone(), |el, keybinding_target| {
588                            el.context(keybinding_target.clone())
589                        })
590                        .action("Fetch", git::Fetch.boxed_clone())
591                        .action("Fetch From", git::FetchFrom.boxed_clone())
592                        .action("Pull", git::Pull.boxed_clone())
593                        .separator()
594                        .action("Push", git::Push.boxed_clone())
595                        .action("Push To", git::PushTo.boxed_clone())
596                        .action("Force Push", git::ForcePush.boxed_clone())
597                }))
598            })
599            .anchor(Corner::TopRight)
600    }
601
602    #[allow(clippy::too_many_arguments)]
603    fn split_button(
604        id: SharedString,
605        left_label: impl Into<SharedString>,
606        ahead_count: usize,
607        behind_count: usize,
608        left_icon: Option<IconName>,
609        keybinding_target: Option<FocusHandle>,
610        left_on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
611        tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
612    ) -> SplitButton {
613        fn count(count: usize) -> impl IntoElement {
614            h_flex()
615                .ml_neg_px()
616                .h(rems(0.875))
617                .items_center()
618                .overflow_hidden()
619                .px_0p5()
620                .child(
621                    Label::new(count.to_string())
622                        .size(LabelSize::XSmall)
623                        .line_height_style(LineHeightStyle::UiLabel),
624                )
625        }
626
627        let should_render_counts = left_icon.is_none() && (ahead_count > 0 || behind_count > 0);
628
629        let left = ui::ButtonLike::new_rounded_left(ElementId::Name(
630            format!("split-button-left-{}", id).into(),
631        ))
632        .layer(ui::ElevationIndex::ModalSurface)
633        .size(ui::ButtonSize::Compact)
634        .when(should_render_counts, |this| {
635            this.child(
636                h_flex()
637                    .ml_neg_0p5()
638                    .mr_1()
639                    .when(behind_count > 0, |this| {
640                        this.child(Icon::new(IconName::ArrowDown).size(IconSize::XSmall))
641                            .child(count(behind_count))
642                    })
643                    .when(ahead_count > 0, |this| {
644                        this.child(Icon::new(IconName::ArrowUp).size(IconSize::XSmall))
645                            .child(count(ahead_count))
646                    }),
647            )
648        })
649        .when_some(left_icon, |this, left_icon| {
650            this.child(
651                h_flex()
652                    .ml_neg_0p5()
653                    .mr_1()
654                    .child(Icon::new(left_icon).size(IconSize::XSmall)),
655            )
656        })
657        .child(
658            div()
659                .child(Label::new(left_label).size(LabelSize::Small))
660                .mr_0p5(),
661        )
662        .on_click(left_on_click)
663        .tooltip(tooltip);
664
665        let right = render_git_action_menu(
666            ElementId::Name(format!("split-button-right-{}", id).into()),
667            keybinding_target,
668        )
669        .into_any_element();
670
671        SplitButton::new(left, right)
672    }
673}
674
675/// A visual representation of a file's Git status.
676#[derive(IntoElement, RegisterComponent)]
677pub struct GitStatusIcon {
678    status: FileStatus,
679}
680
681impl GitStatusIcon {
682    pub fn new(status: FileStatus) -> Self {
683        Self { status }
684    }
685}
686
687impl RenderOnce for GitStatusIcon {
688    fn render(self, _window: &mut ui::Window, cx: &mut App) -> impl IntoElement {
689        let status = self.status;
690
691        let (icon_name, color) = if status.is_conflicted() {
692            (
693                IconName::Warning,
694                cx.theme().colors().version_control_conflict,
695            )
696        } else if status.is_deleted() {
697            (
698                IconName::SquareMinus,
699                cx.theme().colors().version_control_deleted,
700            )
701        } else if status.is_modified() {
702            (
703                IconName::SquareDot,
704                cx.theme().colors().version_control_modified,
705            )
706        } else {
707            (
708                IconName::SquarePlus,
709                cx.theme().colors().version_control_added,
710            )
711        };
712
713        Icon::new(icon_name).color(Color::Custom(color))
714    }
715}
716
717// View this component preview using `workspace: open component-preview`
718impl Component for GitStatusIcon {
719    fn scope() -> ComponentScope {
720        ComponentScope::VersionControl
721    }
722
723    fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
724        fn tracked_file_status(code: StatusCode) -> FileStatus {
725            FileStatus::Tracked(git::status::TrackedStatus {
726                index_status: code,
727                worktree_status: code,
728            })
729        }
730
731        let modified = tracked_file_status(StatusCode::Modified);
732        let added = tracked_file_status(StatusCode::Added);
733        let deleted = tracked_file_status(StatusCode::Deleted);
734        let conflict = UnmergedStatus {
735            first_head: UnmergedStatusCode::Updated,
736            second_head: UnmergedStatusCode::Updated,
737        }
738        .into();
739
740        Some(
741            v_flex()
742                .gap_6()
743                .children(vec![example_group(vec![
744                    single_example("Modified", GitStatusIcon::new(modified).into_any_element()),
745                    single_example("Added", GitStatusIcon::new(added).into_any_element()),
746                    single_example("Deleted", GitStatusIcon::new(deleted).into_any_element()),
747                    single_example(
748                        "Conflicted",
749                        GitStatusIcon::new(conflict).into_any_element(),
750                    ),
751                ])])
752                .into_any_element(),
753        )
754    }
755}
756
757struct GitCloneModal {
758    panel: Entity<GitPanel>,
759    repo_input: Entity<Editor>,
760    focus_handle: FocusHandle,
761}
762
763impl GitCloneModal {
764    pub fn show(panel: Entity<GitPanel>, window: &mut Window, cx: &mut Context<Self>) -> Self {
765        let repo_input = cx.new(|cx| {
766            let mut editor = Editor::single_line(window, cx);
767            editor.set_placeholder_text("Enter repository", cx);
768            editor
769        });
770        let focus_handle = repo_input.focus_handle(cx);
771
772        window.focus(&focus_handle);
773
774        Self {
775            panel,
776            repo_input,
777            focus_handle,
778        }
779    }
780
781    fn render_editor(&self, window: &Window, cx: &App) -> impl IntoElement {
782        let settings = ThemeSettings::get_global(cx);
783        let theme = cx.theme();
784
785        let text_style = TextStyle {
786            color: cx.theme().colors().text,
787            font_family: settings.buffer_font.family.clone(),
788            font_features: settings.buffer_font.features.clone(),
789            font_size: settings.buffer_font_size(cx).into(),
790            font_weight: settings.buffer_font.weight,
791            line_height: relative(settings.buffer_line_height.value()),
792            background_color: Some(theme.colors().editor_background),
793            ..Default::default()
794        };
795
796        let element = EditorElement::new(
797            &self.repo_input,
798            EditorStyle {
799                background: theme.colors().editor_background,
800                local_player: theme.players().local(),
801                text: text_style,
802                ..Default::default()
803            },
804        );
805
806        div()
807            .rounded_md()
808            .p_1()
809            .border_1()
810            .border_color(theme.colors().border_variant)
811            .when(
812                self.repo_input
813                    .focus_handle(cx)
814                    .contains_focused(window, cx),
815                |this| this.border_color(theme.colors().border_focused),
816            )
817            .child(element)
818            .bg(theme.colors().editor_background)
819    }
820}
821
822impl Focusable for GitCloneModal {
823    fn focus_handle(&self, _: &App) -> FocusHandle {
824        self.focus_handle.clone()
825    }
826}
827
828impl Render for GitCloneModal {
829    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
830        div()
831            .size_full()
832            .w(rems(34.))
833            .elevation_3(cx)
834            .child(self.render_editor(window, cx))
835            .on_action(cx.listener(|_, _: &menu::Cancel, _, cx| {
836                cx.emit(DismissEvent);
837            }))
838            .on_action(cx.listener(|this, _: &menu::Confirm, window, cx| {
839                let repo = this.repo_input.read(cx).text(cx);
840                this.panel.update(cx, |panel, cx| {
841                    panel.git_clone(repo, window, cx);
842                });
843                cx.emit(DismissEvent);
844            }))
845    }
846}
847
848impl EventEmitter<DismissEvent> for GitCloneModal {}
849
850impl ModalView for GitCloneModal {}