fix modal exchange (#3620)

- Fix opening GoToLine from Command
- Extend test to cover go_to_line behavior too

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin
2023-12-12 21:30:34 -07:00
committed by GitHub
6 changed files with 88 additions and 36 deletions
+21 -5
View File
@@ -53,6 +53,7 @@ pub struct FeedbackModal {
email_address_editor: View<Editor>,
awaiting_submission: bool,
user_submitted: bool,
discarded: bool,
character_count: i32,
}
@@ -64,21 +65,35 @@ impl FocusableView for FeedbackModal {
impl EventEmitter<DismissEvent> for FeedbackModal {}
impl ModalView for FeedbackModal {
fn dismiss(&mut self, cx: &mut ViewContext<Self>) -> Task<bool> {
fn on_before_dismiss(&mut self, cx: &mut ViewContext<Self>) -> bool {
if self.user_submitted {
self.set_user_submitted(false, cx);
return cx.spawn(|_, _| async { true });
return true;
}
if self.discarded {
return true;
}
let has_feedback = self.feedback_editor.read(cx).text_option(cx).is_some();
if !has_feedback {
return cx.spawn(|_, _| async { true });
return true;
}
let answer = cx.prompt(PromptLevel::Info, "Discard feedback?", &["Yes", "No"]);
cx.spawn(|_, _| async { answer.await.ok() == Some(0) })
cx.spawn(move |this, mut cx| async move {
if answer.await.ok() == Some(0) {
this.update(&mut cx, |this, cx| {
this.discarded = true;
cx.emit(DismissEvent)
})
.log_err();
}
})
.detach();
false
}
}
@@ -169,6 +184,7 @@ impl FeedbackModal {
email_address_editor,
awaiting_submission: false,
user_submitted: false,
discarded: false,
character_count: 0,
}
}