From e10360713453d98a3a7befc54a0379b1757decb5 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:08:55 +0100 Subject: [PATCH] copilot: Track focus of modal + close modal on ESC (#9217) I've also made Copilot's modal regain focus whenever you click on it, as otherwise there's nothing inside of it that can gain focus. Clicks do not fall through a modal, which I think is nice. Release Notes: - Fixed the issue where pressing ESC (`menu::Cancel`) did not exit the Copilot modal. Fixes #8852 --- Cargo.lock | 1 + crates/copilot_ui/Cargo.toml | 1 + crates/copilot_ui/src/sign_in.rs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf51b63dea66812217e1a0b78b49876978ef619d..83ed064e60320063143e851f8b8076ff4dc01abb 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 cc184b2dfc75b5a186928844024fbf2bd3a7abf7..d35c13699ad699b6650088308b493c1e5e09cf3a 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 976d5f8b3e7ddb550d994664f918a86befb34264..bc2c5b7c6fa1e5d488ea80e284619529460fe0a3 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()