Skip to content

Commit c499cb9

Browse files
committed
Prevent Escape from dismissing network questions
AI-assisted: OpenAI Codex helped investigate, implement, test, and review this change. I reviewed and understand the final changes.
1 parent 892ae20 commit c499cb9

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

src/app.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,14 @@ impl DialogPages {
672672
matches!(self.pages.front(), Some(DialogPage::NetworkQuestion { .. }))
673673
}
674674

675+
fn pop_front_for_escape(&mut self) -> Option<(DialogPage, Task<Message>)> {
676+
if self.front_is_network_question() {
677+
None
678+
} else {
679+
self.pop_front()
680+
}
681+
}
682+
675683
fn pop_network_question(
676684
&mut self,
677685
question_tx: &mpsc::Sender<i32>,
@@ -2825,8 +2833,11 @@ impl Application for App {
28252833
let entity = self.tab_model.active();
28262834

28272835
// Close dialog if open
2828-
if let Some((_page, task)) = self.dialog_pages.pop_front() {
2829-
return task;
2836+
if self.dialog_pages.front().is_some() {
2837+
return self
2838+
.dialog_pages
2839+
.pop_front_for_escape()
2840+
.map_or(Task::none(), |(_page, task)| task);
28302841
}
28312842

28322843
// Close gallery mode if open
@@ -7366,6 +7377,45 @@ mod tests {
73667377
assert!(pages.front().is_none());
73677378
assert_eq!(pages.pages.len(), 0);
73687379
}
7380+
7381+
#[test]
7382+
fn network_question_escape_rejects_stale_input() {
7383+
let (q1_tx, _) = mpsc::channel(1);
7384+
let (q2_tx, _) = mpsc::channel(1);
7385+
let q1 = DialogPage::NetworkQuestion {
7386+
mounter_key: MounterKey("test"),
7387+
uri: String::from("sftp://q1"),
7388+
question: MounterQuestion {
7389+
message: String::from("Q1"),
7390+
choices: vec![String::from("choice")],
7391+
},
7392+
question_tx: q1_tx.clone(),
7393+
};
7394+
let q2 = DialogPage::NetworkQuestion {
7395+
mounter_key: MounterKey("test"),
7396+
uri: String::from("sftp://q2"),
7397+
question: MounterQuestion {
7398+
message: String::from("Q2"),
7399+
choices: vec![String::from("choice")],
7400+
},
7401+
question_tx: q2_tx.clone(),
7402+
};
7403+
let mut pages = DialogPages::new();
7404+
let _ = pages.push_back(q1);
7405+
let _ = pages.push_back(q2);
7406+
7407+
let (_popped, _task) = pages
7408+
.pop_network_question(&q1_tx)
7409+
.expect("matching first network question should pop");
7410+
let page_count = pages.pages.len();
7411+
assert!(pages.pop_front_for_escape().is_none());
7412+
assert_eq!(pages.pages.len(), page_count);
7413+
assert!(matches!(
7414+
pages.front(),
7415+
Some(DialogPage::NetworkQuestion { question_tx, .. })
7416+
if question_tx.same_channel(&q2_tx)
7417+
));
7418+
}
73697419
}
73707420

73717421
// Utilities to build a temporary file hierarchy for tests.

0 commit comments

Comments
 (0)