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 cx.spawn(async move |_, cx| {
280 match repo
281 .update(cx, |repo, _| repo.rename_branch(new_name.clone()))?
282 .await
283 {
284 Ok(Ok(_)) => Ok(()),
285 Ok(Err(error)) => Err(error),
286 Err(_) => Err(anyhow::anyhow!("Operation was canceled")),
287 }
288 })
289 .detach_and_prompt_err("Failed to rename branch", window, cx, |_, _, _| None);
290 cx.emit(DismissEvent);
291 }
292}
293
294impl EventEmitter<DismissEvent> for RenameBranchModal {}
295impl ModalView for RenameBranchModal {}
296impl Focusable for RenameBranchModal {
297 fn focus_handle(&self, cx: &App) -> FocusHandle {
298 self.editor.focus_handle(cx)
299 }
300}
301
302impl Render for RenameBranchModal {
303 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
304 v_flex()
305 .key_context("RenameBranchModal")
306 .on_action(cx.listener(Self::cancel))
307 .on_action(cx.listener(Self::confirm))
308 .elevation_2(cx)
309 .w(rems(34.))
310 .child(
311 h_flex()
312 .px_3()
313 .pt_2()
314 .pb_1()
315 .w_full()
316 .gap_1p5()
317 .child(Icon::new(IconName::GitBranch).size(IconSize::XSmall))
318 .child(
319 Headline::new(format!("Rename Branch ({})", self.current_branch))
320 .size(HeadlineSize::XSmall),
321 ),
322 )
323 .child(div().px_3().pb_3().w_full().child(self.editor.clone()))
324 }
325}
326
327fn rename_current_branch(
328 workspace: &mut Workspace,
329 window: &mut Window,
330 cx: &mut Context<Workspace>,
331) {
332 let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
333 return;
334 };
335 let current_branch: Option<String> = panel.update(cx, |panel, cx| {
336 let repo = panel.active_repository.as_ref()?;
337 let repo = repo.read(cx);
338 repo.branch.as_ref().map(|branch| branch.name().to_string())
339 });
340
341 let Some(current_branch_name) = current_branch else {
342 return;
343 };
344
345 let repo = panel.read(cx).active_repository.clone();
346 let Some(repo) = repo else {
347 return;
348 };
349
350 workspace.toggle_modal(window, cx, |window, cx| {
351 RenameBranchModal::new(current_branch_name, repo, window, cx)
352 });
353}
354
355fn render_remote_button(
356 id: impl Into<SharedString>,
357 branch: &Branch,
358 keybinding_target: Option<FocusHandle>,
359 show_fetch_button: bool,
360) -> Option<impl IntoElement> {
361 let id = id.into();
362 let upstream = branch.upstream.as_ref();
363 match upstream {
364 Some(Upstream {
365 tracking: UpstreamTracking::Tracked(UpstreamTrackingStatus { ahead, behind }),
366 ..
367 }) => match (*ahead, *behind) {
368 (0, 0) if show_fetch_button => {
369 Some(remote_button::render_fetch_button(keybinding_target, id))
370 }
371 (0, 0) => None,
372 (ahead, 0) => Some(remote_button::render_push_button(
373 keybinding_target.clone(),
374 id,
375 ahead,
376 )),
377 (ahead, behind) => Some(remote_button::render_pull_button(
378 keybinding_target.clone(),
379 id,
380 ahead,
381 behind,
382 )),
383 },
384 Some(Upstream {
385 tracking: UpstreamTracking::Gone,
386 ..
387 }) => Some(remote_button::render_republish_button(
388 keybinding_target,
389 id,
390 )),
391 None => Some(remote_button::render_publish_button(keybinding_target, id)),
392 }
393}
394
395mod remote_button {
396 use gpui::{Action, AnyView, ClickEvent, Corner, FocusHandle};
397 use ui::{
398 App, ButtonCommon, Clickable, ContextMenu, ElementId, FluentBuilder, Icon, IconName,
399 IconSize, IntoElement, Label, LabelCommon, LabelSize, LineHeightStyle, ParentElement,
400 PopoverMenu, SharedString, SplitButton, Styled, Tooltip, Window, div, h_flex, rems,
401 };
402
403 pub fn render_fetch_button(
404 keybinding_target: Option<FocusHandle>,
405 id: SharedString,
406 ) -> SplitButton {
407 split_button(
408 id,
409 "Fetch",
410 0,
411 0,
412 Some(IconName::ArrowCircle),
413 keybinding_target.clone(),
414 move |_, window, cx| {
415 window.dispatch_action(Box::new(git::Fetch), cx);
416 },
417 move |window, cx| {
418 git_action_tooltip(
419 "Fetch updates from remote",
420 &git::Fetch,
421 "git fetch",
422 keybinding_target.clone(),
423 window,
424 cx,
425 )
426 },
427 )
428 }
429
430 pub fn render_push_button(
431 keybinding_target: Option<FocusHandle>,
432 id: SharedString,
433 ahead: u32,
434 ) -> SplitButton {
435 split_button(
436 id,
437 "Push",
438 ahead as usize,
439 0,
440 None,
441 keybinding_target.clone(),
442 move |_, window, cx| {
443 window.dispatch_action(Box::new(git::Push), cx);
444 },
445 move |window, cx| {
446 git_action_tooltip(
447 "Push committed changes to remote",
448 &git::Push,
449 "git push",
450 keybinding_target.clone(),
451 window,
452 cx,
453 )
454 },
455 )
456 }
457
458 pub fn render_pull_button(
459 keybinding_target: Option<FocusHandle>,
460 id: SharedString,
461 ahead: u32,
462 behind: u32,
463 ) -> SplitButton {
464 split_button(
465 id,
466 "Pull",
467 ahead as usize,
468 behind as usize,
469 None,
470 keybinding_target.clone(),
471 move |_, window, cx| {
472 window.dispatch_action(Box::new(git::Pull), cx);
473 },
474 move |window, cx| {
475 git_action_tooltip(
476 "Pull",
477 &git::Pull,
478 "git pull",
479 keybinding_target.clone(),
480 window,
481 cx,
482 )
483 },
484 )
485 }
486
487 pub fn render_publish_button(
488 keybinding_target: Option<FocusHandle>,
489 id: SharedString,
490 ) -> SplitButton {
491 split_button(
492 id,
493 "Publish",
494 0,
495 0,
496 Some(IconName::ExpandUp),
497 keybinding_target.clone(),
498 move |_, window, cx| {
499 window.dispatch_action(Box::new(git::Push), cx);
500 },
501 move |window, cx| {
502 git_action_tooltip(
503 "Publish branch to remote",
504 &git::Push,
505 "git push --set-upstream",
506 keybinding_target.clone(),
507 window,
508 cx,
509 )
510 },
511 )
512 }
513
514 pub fn render_republish_button(
515 keybinding_target: Option<FocusHandle>,
516 id: SharedString,
517 ) -> SplitButton {
518 split_button(
519 id,
520 "Republish",
521 0,
522 0,
523 Some(IconName::ExpandUp),
524 keybinding_target.clone(),
525 move |_, window, cx| {
526 window.dispatch_action(Box::new(git::Push), cx);
527 },
528 move |window, cx| {
529 git_action_tooltip(
530 "Re-publish branch to remote",
531 &git::Push,
532 "git push --set-upstream",
533 keybinding_target.clone(),
534 window,
535 cx,
536 )
537 },
538 )
539 }
540
541 fn git_action_tooltip(
542 label: impl Into<SharedString>,
543 action: &dyn Action,
544 command: impl Into<SharedString>,
545 focus_handle: Option<FocusHandle>,
546 window: &mut Window,
547 cx: &mut App,
548 ) -> AnyView {
549 let label = label.into();
550 let command = command.into();
551
552 if let Some(handle) = focus_handle {
553 Tooltip::with_meta_in(
554 label.clone(),
555 Some(action),
556 command.clone(),
557 &handle,
558 window,
559 cx,
560 )
561 } else {
562 Tooltip::with_meta(label.clone(), Some(action), command.clone(), window, cx)
563 }
564 }
565
566 fn render_git_action_menu(
567 id: impl Into<ElementId>,
568 keybinding_target: Option<FocusHandle>,
569 ) -> impl IntoElement {
570 PopoverMenu::new(id.into())
571 .trigger(
572 ui::ButtonLike::new_rounded_right("split-button-right")
573 .layer(ui::ElevationIndex::ModalSurface)
574 .size(ui::ButtonSize::None)
575 .child(
576 div()
577 .px_1()
578 .child(Icon::new(IconName::ChevronDown).size(IconSize::XSmall)),
579 ),
580 )
581 .menu(move |window, cx| {
582 Some(ContextMenu::build(window, cx, |context_menu, _, _| {
583 context_menu
584 .when_some(keybinding_target.clone(), |el, keybinding_target| {
585 el.context(keybinding_target.clone())
586 })
587 .action("Fetch", git::Fetch.boxed_clone())
588 .action("Fetch From", git::FetchFrom.boxed_clone())
589 .action("Pull", git::Pull.boxed_clone())
590 .separator()
591 .action("Push", git::Push.boxed_clone())
592 .action("Push To", git::PushTo.boxed_clone())
593 .action("Force Push", git::ForcePush.boxed_clone())
594 }))
595 })
596 .anchor(Corner::TopRight)
597 }
598
599 #[allow(clippy::too_many_arguments)]
600 fn split_button(
601 id: SharedString,
602 left_label: impl Into<SharedString>,
603 ahead_count: usize,
604 behind_count: usize,
605 left_icon: Option<IconName>,
606 keybinding_target: Option<FocusHandle>,
607 left_on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
608 tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
609 ) -> SplitButton {
610 fn count(count: usize) -> impl IntoElement {
611 h_flex()
612 .ml_neg_px()
613 .h(rems(0.875))
614 .items_center()
615 .overflow_hidden()
616 .px_0p5()
617 .child(
618 Label::new(count.to_string())
619 .size(LabelSize::XSmall)
620 .line_height_style(LineHeightStyle::UiLabel),
621 )
622 }
623
624 let should_render_counts = left_icon.is_none() && (ahead_count > 0 || behind_count > 0);
625
626 let left = ui::ButtonLike::new_rounded_left(ElementId::Name(
627 format!("split-button-left-{}", id).into(),
628 ))
629 .layer(ui::ElevationIndex::ModalSurface)
630 .size(ui::ButtonSize::Compact)
631 .when(should_render_counts, |this| {
632 this.child(
633 h_flex()
634 .ml_neg_0p5()
635 .mr_1()
636 .when(behind_count > 0, |this| {
637 this.child(Icon::new(IconName::ArrowDown).size(IconSize::XSmall))
638 .child(count(behind_count))
639 })
640 .when(ahead_count > 0, |this| {
641 this.child(Icon::new(IconName::ArrowUp).size(IconSize::XSmall))
642 .child(count(ahead_count))
643 }),
644 )
645 })
646 .when_some(left_icon, |this, left_icon| {
647 this.child(
648 h_flex()
649 .ml_neg_0p5()
650 .mr_1()
651 .child(Icon::new(left_icon).size(IconSize::XSmall)),
652 )
653 })
654 .child(
655 div()
656 .child(Label::new(left_label).size(LabelSize::Small))
657 .mr_0p5(),
658 )
659 .on_click(left_on_click)
660 .tooltip(tooltip);
661
662 let right = render_git_action_menu(
663 ElementId::Name(format!("split-button-right-{}", id).into()),
664 keybinding_target,
665 )
666 .into_any_element();
667
668 SplitButton::new(left, right)
669 }
670}
671
672/// A visual representation of a file's Git status.
673#[derive(IntoElement, RegisterComponent)]
674pub struct GitStatusIcon {
675 status: FileStatus,
676}
677
678impl GitStatusIcon {
679 pub fn new(status: FileStatus) -> Self {
680 Self { status }
681 }
682}
683
684impl RenderOnce for GitStatusIcon {
685 fn render(self, _window: &mut ui::Window, cx: &mut App) -> impl IntoElement {
686 let status = self.status;
687
688 let (icon_name, color) = if status.is_conflicted() {
689 (
690 IconName::Warning,
691 cx.theme().colors().version_control_conflict,
692 )
693 } else if status.is_deleted() {
694 (
695 IconName::SquareMinus,
696 cx.theme().colors().version_control_deleted,
697 )
698 } else if status.is_modified() {
699 (
700 IconName::SquareDot,
701 cx.theme().colors().version_control_modified,
702 )
703 } else {
704 (
705 IconName::SquarePlus,
706 cx.theme().colors().version_control_added,
707 )
708 };
709
710 Icon::new(icon_name).color(Color::Custom(color))
711 }
712}
713
714// View this component preview using `workspace: open component-preview`
715impl Component for GitStatusIcon {
716 fn scope() -> ComponentScope {
717 ComponentScope::VersionControl
718 }
719
720 fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
721 fn tracked_file_status(code: StatusCode) -> FileStatus {
722 FileStatus::Tracked(git::status::TrackedStatus {
723 index_status: code,
724 worktree_status: code,
725 })
726 }
727
728 let modified = tracked_file_status(StatusCode::Modified);
729 let added = tracked_file_status(StatusCode::Added);
730 let deleted = tracked_file_status(StatusCode::Deleted);
731 let conflict = UnmergedStatus {
732 first_head: UnmergedStatusCode::Updated,
733 second_head: UnmergedStatusCode::Updated,
734 }
735 .into();
736
737 Some(
738 v_flex()
739 .gap_6()
740 .children(vec![example_group(vec![
741 single_example("Modified", GitStatusIcon::new(modified).into_any_element()),
742 single_example("Added", GitStatusIcon::new(added).into_any_element()),
743 single_example("Deleted", GitStatusIcon::new(deleted).into_any_element()),
744 single_example(
745 "Conflicted",
746 GitStatusIcon::new(conflict).into_any_element(),
747 ),
748 ])])
749 .into_any_element(),
750 )
751 }
752}
753
754struct GitCloneModal {
755 panel: Entity<GitPanel>,
756 repo_input: Entity<Editor>,
757 focus_handle: FocusHandle,
758}
759
760impl GitCloneModal {
761 pub fn show(panel: Entity<GitPanel>, window: &mut Window, cx: &mut Context<Self>) -> Self {
762 let repo_input = cx.new(|cx| {
763 let mut editor = Editor::single_line(window, cx);
764 editor.set_placeholder_text("Enter repository", cx);
765 editor
766 });
767 let focus_handle = repo_input.focus_handle(cx);
768
769 window.focus(&focus_handle);
770
771 Self {
772 panel,
773 repo_input,
774 focus_handle,
775 }
776 }
777
778 fn render_editor(&self, window: &Window, cx: &App) -> impl IntoElement {
779 let settings = ThemeSettings::get_global(cx);
780 let theme = cx.theme();
781
782 let text_style = TextStyle {
783 color: cx.theme().colors().text,
784 font_family: settings.buffer_font.family.clone(),
785 font_features: settings.buffer_font.features.clone(),
786 font_size: settings.buffer_font_size(cx).into(),
787 font_weight: settings.buffer_font.weight,
788 line_height: relative(settings.buffer_line_height.value()),
789 background_color: Some(theme.colors().editor_background),
790 ..Default::default()
791 };
792
793 let element = EditorElement::new(
794 &self.repo_input,
795 EditorStyle {
796 background: theme.colors().editor_background,
797 local_player: theme.players().local(),
798 text: text_style,
799 ..Default::default()
800 },
801 );
802
803 div()
804 .rounded_md()
805 .p_1()
806 .border_1()
807 .border_color(theme.colors().border_variant)
808 .when(
809 self.repo_input
810 .focus_handle(cx)
811 .contains_focused(window, cx),
812 |this| this.border_color(theme.colors().border_focused),
813 )
814 .child(element)
815 .bg(theme.colors().editor_background)
816 }
817}
818
819impl Focusable for GitCloneModal {
820 fn focus_handle(&self, _: &App) -> FocusHandle {
821 self.focus_handle.clone()
822 }
823}
824
825impl Render for GitCloneModal {
826 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
827 div()
828 .size_full()
829 .w(rems(34.))
830 .elevation_3(cx)
831 .child(self.render_editor(window, cx))
832 .on_action(cx.listener(|_, _: &menu::Cancel, _, cx| {
833 cx.emit(DismissEvent);
834 }))
835 .on_action(cx.listener(|this, _: &menu::Confirm, window, cx| {
836 let repo = this.repo_input.read(cx).text(cx);
837 this.panel.update(cx, |panel, cx| {
838 panel.git_clone(repo, window, cx);
839 });
840 cx.emit(DismissEvent);
841 }))
842 }
843}
844
845impl EventEmitter<DismissEvent> for GitCloneModal {}
846
847impl ModalView for GitCloneModal {}