Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

copilot: Track focus of modal + close modal on ESC (#9217)

Piotr Osiewicze10360713453
diff --git a/Cargo.lock b/Cargo.lock
index cf51b63dea6..83ed064e603 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2493,6 +2493,7 @@ dependencies = [
"fs",
"gpui",
"language",
+ "menu",
"settings",
"ui",
"util",
diff --git a/crates/copilot_ui/Cargo.toml b/crates/copilot_ui/Cargo.toml
index cc184b2dfc7..d35c13699ad 100644
--- a/crates/copilot_ui/Cargo.toml
+++ b/crates/copilot_ui/Cargo.toml
@@ -19,6 +19,7 @@ editor.workspace = true
fs.workspace = true
gpui.workspace = true
language.workspace = true
+menu.workspace = true
settings.workspace = true
ui.workspace = true
util.workspace = true
diff --git a/crates/copilot_ui/src/sign_in.rs b/crates/copilot_ui/src/sign_in.rs
index 976d5f8b3e7..bc2c5b7c6fa 100644
--- a/crates/copilot_ui/src/sign_in.rs
+++ b/crates/copilot_ui/src/sign_in.rs
@@ -1,8 +1,8 @@
use copilot::{request::PromptUserDeviceFlow, Copilot, Status};
use gpui::{
div, svg, AppContext, ClipboardItem, DismissEvent, Element, EventEmitter, FocusHandle,
- FocusableView, InteractiveElement, IntoElement, Model, ParentElement, Render, Styled,
- Subscription, ViewContext,
+ FocusableView, InteractiveElement, IntoElement, Model, MouseDownEvent, ParentElement, Render,
+ Styled, Subscription, ViewContext,
};
use ui::{prelude::*, Button, IconName, Label};
use workspace::ModalView;
@@ -185,11 +185,19 @@ impl Render for CopilotCodeVerification {
v_flex()
.id("copilot code verification")
+ .track_focus(&self.focus_handle)
.elevation_3(cx)
.w_96()
.items_center()
.p_4()
.gap_2()
+ .on_action(cx.listener(|_, _: &menu::Cancel, cx| {
+ cx.emit(DismissEvent);
+ }))
+ .capture_any_mouse_down(cx.listener(|this, _: &MouseDownEvent, cx| {
+ cx.focus(&this.focus_handle);
+ cx.stop_propagation();
+ }))
.child(
svg()
.w_32()