mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-25 22:01:47 +03:00
Avoid another confirmation when submitting/discarding feedback (#7569)
Fixes https://github.com/zed-industries/zed/issues/7515 Release Notes: - Fixed feedback modal spawning extra confirmations on cancel and submit ([7515](https://github.com/zed-industries/zed/issues/7515))
This commit is contained in:
parent
d457eef099
commit
f734365b7b
@ -17,7 +17,7 @@ use regex::Regex;
|
||||
use serde_derive::Serialize;
|
||||
use ui::{prelude::*, Button, ButtonStyle, IconPosition, Tooltip};
|
||||
use util::{http::HttpClient, ResultExt};
|
||||
use workspace::{ModalView, Toast, Workspace};
|
||||
use workspace::{DismissDecision, ModalView, Toast, Workspace};
|
||||
|
||||
use crate::{system_specs::SystemSpecs, GiveFeedback, OpenZedRepo};
|
||||
|
||||
@ -85,16 +85,16 @@ impl FocusableView for FeedbackModal {
|
||||
impl EventEmitter<DismissEvent> for FeedbackModal {}
|
||||
|
||||
impl ModalView for FeedbackModal {
|
||||
fn on_before_dismiss(&mut self, cx: &mut ViewContext<Self>) -> bool {
|
||||
fn on_before_dismiss(&mut self, cx: &mut ViewContext<Self>) -> DismissDecision {
|
||||
self.update_email_in_store(cx);
|
||||
|
||||
if self.dismiss_modal {
|
||||
return true;
|
||||
return DismissDecision::Dismiss(true);
|
||||
}
|
||||
|
||||
let has_feedback = self.feedback_editor.read(cx).text_option(cx).is_some();
|
||||
if !has_feedback {
|
||||
return true;
|
||||
return DismissDecision::Dismiss(true);
|
||||
}
|
||||
|
||||
let answer = cx.prompt(PromptLevel::Info, "Discard feedback?", None, &["Yes", "No"]);
|
||||
@ -110,7 +110,7 @@ impl ModalView for FeedbackModal {
|
||||
})
|
||||
.detach();
|
||||
|
||||
false
|
||||
DismissDecision::Pending
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ use std::{
|
||||
use theme::{color_alpha, ActiveTheme, ThemeSettings};
|
||||
use ui::{prelude::*, ListItem, ListItemSpacing};
|
||||
use util::ResultExt;
|
||||
use workspace::ModalView;
|
||||
use workspace::{DismissDecision, ModalView};
|
||||
|
||||
actions!(outline, [Toggle]);
|
||||
|
||||
@ -55,10 +55,10 @@ impl FocusableView for OutlineView {
|
||||
|
||||
impl EventEmitter<DismissEvent> for OutlineView {}
|
||||
impl ModalView for OutlineView {
|
||||
fn on_before_dismiss(&mut self, cx: &mut ViewContext<Self>) -> bool {
|
||||
fn on_before_dismiss(&mut self, cx: &mut ViewContext<Self>) -> DismissDecision {
|
||||
self.picker
|
||||
.update(cx, |picker, cx| picker.delegate.restore_active_editor(cx));
|
||||
true
|
||||
DismissDecision::Dismiss(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,19 +4,24 @@ use gpui::{
|
||||
};
|
||||
use ui::{h_flex, v_flex};
|
||||
|
||||
pub enum DismissDecision {
|
||||
Dismiss(bool),
|
||||
Pending,
|
||||
}
|
||||
|
||||
pub trait ModalView: ManagedView {
|
||||
fn on_before_dismiss(&mut self, _: &mut ViewContext<Self>) -> bool {
|
||||
true
|
||||
fn on_before_dismiss(&mut self, _: &mut ViewContext<Self>) -> DismissDecision {
|
||||
DismissDecision::Dismiss(true)
|
||||
}
|
||||
}
|
||||
|
||||
trait ModalViewHandle {
|
||||
fn on_before_dismiss(&mut self, cx: &mut WindowContext) -> bool;
|
||||
fn on_before_dismiss(&mut self, cx: &mut WindowContext) -> DismissDecision;
|
||||
fn view(&self) -> AnyView;
|
||||
}
|
||||
|
||||
impl<V: ModalView> ModalViewHandle for View<V> {
|
||||
fn on_before_dismiss(&mut self, cx: &mut WindowContext) -> bool {
|
||||
fn on_before_dismiss(&mut self, cx: &mut WindowContext) -> DismissDecision {
|
||||
self.update(cx, |this, cx| this.on_before_dismiss(cx))
|
||||
}
|
||||
|
||||
@ -34,11 +39,15 @@ pub struct ActiveModal {
|
||||
|
||||
pub struct ModalLayer {
|
||||
active_modal: Option<ActiveModal>,
|
||||
dismiss_on_focus_lost: bool,
|
||||
}
|
||||
|
||||
impl ModalLayer {
|
||||
pub fn new() -> Self {
|
||||
Self { active_modal: None }
|
||||
Self {
|
||||
active_modal: None,
|
||||
dismiss_on_focus_lost: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle_modal<V, B>(&mut self, cx: &mut ViewContext<Self>, build_view: B)
|
||||
@ -69,7 +78,9 @@ impl ModalLayer {
|
||||
this.hide_modal(cx);
|
||||
}),
|
||||
cx.on_focus_out(&focus_handle, |this, cx| {
|
||||
if this.dismiss_on_focus_lost {
|
||||
this.hide_modal(cx);
|
||||
}
|
||||
}),
|
||||
],
|
||||
previous_focus_handle: cx.focused(),
|
||||
@ -81,13 +92,22 @@ impl ModalLayer {
|
||||
|
||||
fn hide_modal(&mut self, cx: &mut ViewContext<Self>) -> bool {
|
||||
let Some(active_modal) = self.active_modal.as_mut() else {
|
||||
self.dismiss_on_focus_lost = false;
|
||||
return false;
|
||||
};
|
||||
|
||||
let dismiss = active_modal.modal.on_before_dismiss(cx);
|
||||
match active_modal.modal.on_before_dismiss(cx) {
|
||||
DismissDecision::Dismiss(dismiss) => {
|
||||
self.dismiss_on_focus_lost = !dismiss;
|
||||
if !dismiss {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DismissDecision::Pending => {
|
||||
self.dismiss_on_focus_lost = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(active_modal) = self.active_modal.take() {
|
||||
if let Some(previous_focus) = active_modal.previous_focus_handle {
|
||||
|
Loading…
Reference in New Issue
Block a user