Esc while there are queued messages drops the messages back into the composer (#2687)

https://github.com/user-attachments/assets/bbb427c4-cdc7-4997-a4ef-8156e8170742
This commit is contained in:
Jeremy Rose
2025-08-26 16:26:50 -07:00
committed by GitHub
parent eb161116f0
commit f2603a4e50
3 changed files with 75 additions and 5 deletions

View File

@@ -243,20 +243,51 @@ impl ChatWidget {
);
}
fn on_error(&mut self, message: String) {
// Before emitting the error message, finalize the active exec as failed
// so spinners are replaced with a red ✗ marker.
/// Finalize any active exec as failed, push an error message into history,
/// and stop/clear running UI state.
fn finalize_turn_with_error_message(&mut self, message: String) {
// Ensure any spinner is replaced by a red ✗ and flushed into history.
self.finalize_active_exec_cell_as_failed();
// Emit the provided error message/history cell.
self.add_to_history(history_cell::new_error_event(message));
// Reset running state and clear streaming buffers.
self.bottom_pane.set_task_running(false);
self.running_commands.clear();
self.stream.clear_all();
}
fn on_error(&mut self, message: String) {
self.finalize_turn_with_error_message(message);
self.request_redraw();
// After an error ends the turn, try sending the next queued input.
self.maybe_send_next_queued_input();
}
/// Handle a turn aborted due to user interrupt (Esc).
/// When there are queued user messages, restore them into the composer
/// separated by newlines rather than autosubmitting the next one.
fn on_interrupted_turn(&mut self) {
// Finalize, log a gentle prompt, and clear running state.
self.finalize_turn_with_error_message("Tell the model what to do differently".to_owned());
// If any messages were queued during the task, restore them into the composer.
if !self.queued_user_messages.is_empty() {
let combined = self
.queued_user_messages
.iter()
.map(|m| m.text.clone())
.collect::<Vec<_>>()
.join("\n");
self.bottom_pane.set_composer_text(combined);
// Clear the queue and update the status indicator list.
self.queued_user_messages.clear();
self.refresh_queued_user_messages();
}
self.request_redraw();
}
fn on_plan_update(&mut self, update: codex_core::plan_tool::UpdatePlanArgs) {
self.add_to_history(history_cell::new_plan_update(update));
}
@@ -913,7 +944,7 @@ impl ChatWidget {
EventMsg::Error(ErrorEvent { message }) => self.on_error(message),
EventMsg::TurnAborted(ev) => match ev.reason {
TurnAbortReason::Interrupted => {
self.on_error("Tell the model what to do differently".to_owned())
self.on_interrupted_turn();
}
TurnAbortReason::Replaced => {
self.on_error("Turn aborted: replaced by a new task".to_owned())