You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/24 18:06:19 UTC
(maka) 06/17: feat(desktop): stop a running turn with Esc pressed twice
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch feat/desktop-gpui-spike
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 7ebc0cb4ea085da3d6f1f3f0f2f6acaa6255b343
Author: AstroHan <le...@outlook.com>
AuthorDate: Fri Sep 25 01:52:10 2026 +0800
feat(desktop): stop a running turn with Esc pressed twice
Stopping needed the mouse or several Tab presses. The first Esc while a
turn runs shows "再按一次 Esc 停止" above the composer for 1.5 s; a
second Esc in that time stops the turn. Esc reaches the chat from the
transcript through a binding and from the composer once the text field
has nothing left to dismiss; with no turn running it passes on.
Generated-by: Claude Code
---
crates/desktop/src/chat/composer.rs | 1 +
crates/desktop/src/chat/mod.rs | 31 +++++++++++++++++++++++++++++--
crates/desktop/src/chat/view.rs | 14 +++++++++++++-
crates/desktop/src/main.rs | 1 +
4 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/crates/desktop/src/chat/composer.rs b/crates/desktop/src/chat/composer.rs
index e249665e70..740554062e 100644
--- a/crates/desktop/src/chat/composer.rs
+++ b/crates/desktop/src/chat/composer.rs
@@ -33,6 +33,7 @@ impl Chat {
pub(super) fn render_composer(&self, cx: &mut Context<Self>) -> impl IntoElement {
let theme = theme(cx);
let status: Option<SharedString> = match &self.delivery {
+ _ if self.stop_armed.is_some() => Some("再按一次 Esc 停止".into()),
Some(Delivery::Failed(error)) => Some(format!("未发送:{error}").into()),
Some(Delivery::Unknown { error, .. }) => Some(
format!("发送结果未知({error})。消息出现在对话中即已送达;修改草稿可重新发送。")
diff --git a/crates/desktop/src/chat/mod.rs b/crates/desktop/src/chat/mod.rs
index 11354e312f..7a2d1f69d5 100644
--- a/crates/desktop/src/chat/mod.rs
+++ b/crates/desktop/src/chat/mod.rs
@@ -31,7 +31,7 @@ use crate::{
use gpui_kit::base::input::{InputEvent, TextareaState};
use gpui_kit::{
AnyWindowHandle, AppContext, Context, Entity, FocusHandle, FollowMode, ListAlignment,
- ListOffset, ListState, Pixels, SharedString, Subscription, Window, px,
+ ListOffset, ListState, Pixels, SharedString, Subscription, Task, Window, px,
};
use maka_client::{
Client, RequestFailure,
@@ -60,7 +60,10 @@ const PAGE_BYTES: u64 = 64 * 1024;
/// Streaming changes the height of the reply and of the rows around it.
const TAIL_ROWS: usize = 3;
-gpui_kit::actions!(transcript, [CopySelection]);
+gpui_kit::actions!(transcript, [CopySelection, Interrupt]);
+
+/// A second Esc within this long stops the running turn.
+const STOP_CONFIRM: Duration = Duration::from_millis(1500);
enum Delivery {
Sending,
@@ -113,6 +116,8 @@ pub struct Chat {
window: AnyWindowHandle,
delivery: Option<Delivery>,
stopping: bool,
+ /// Set by a first Esc while a turn runs; clears itself.
+ stop_armed: Option<Task<()>>,
answering: Option<String>,
interaction_error: Option<SharedString>,
focus: FocusHandle,
@@ -199,6 +204,7 @@ impl Chat {
window: window.window_handle(),
delivery: None,
stopping: false,
+ stop_armed: None,
answering: None,
interaction_error: None,
focus: cx.focus_handle(),
@@ -619,6 +625,27 @@ impl Chat {
cx.notify();
}
+ /// Esc while a turn runs: the first press asks, the second stops.
+ /// Returns false when there is nothing to stop, so Esc goes on.
+ fn interrupt(&mut self, cx: &mut Context<Self>) -> bool {
+ if self.running().is_none() {
+ return false;
+ }
+ if self.stop_armed.take().is_some() {
+ self.stop(cx);
+ } else {
+ self.stop_armed = Some(cx.spawn(async move |this, cx| {
+ cx.background_executor().timer(STOP_CONFIRM).await;
+ let _ = this.update(cx, |this, cx| {
+ this.stop_armed = None;
+ cx.notify();
+ });
+ }));
+ }
+ cx.notify();
+ true
+ }
+
/// Empties the composer if it still holds the sent text; anything typed
/// since is kept.
fn clear_sent_draft(&self, text: String, cx: &mut Context<Self>) {
diff --git a/crates/desktop/src/chat/view.rs b/crates/desktop/src/chat/view.rs
index 84b550986c..063db706d3 100644
--- a/crates/desktop/src/chat/view.rs
+++ b/crates/desktop/src/chat/view.rs
@@ -31,7 +31,7 @@ use chrono::{Local, TimeZone};
use gpui_kit::{
AnyElement, App, Context, Div, Entity, FontWeight, InteractiveElement, IntoElement,
MouseButton, ParentElement, Render, SharedString, StatefulInteractiveElement, Styled,
- StyledText, Window, div, list, prelude::FluentBuilder, px,
+ StyledText, Window, component::input, div, list, prelude::FluentBuilder, px,
};
use std::time::{Duration, Instant};
@@ -751,6 +751,18 @@ impl Render for Chat {
.size_full()
.flex()
.flex_col()
+ .key_context("Chat")
+ .on_action(cx.listener(|this, _: &super::Interrupt, _, cx| {
+ if !this.interrupt(cx) {
+ cx.propagate();
+ }
+ }))
+ // The composer's own Esc, once it has nothing left to dismiss.
+ .on_action(cx.listener(|this, _: &input::Escape, _, cx| {
+ if !this.interrupt(cx) {
+ cx.propagate();
+ }
+ }))
.bg(theme.base)
.text_color(theme.text)
.child(
diff --git a/crates/desktop/src/main.rs b/crates/desktop/src/main.rs
index 8cc80a7139..0823bb9361 100644
--- a/crates/desktop/src/main.rs
+++ b/crates/desktop/src/main.rs
@@ -82,6 +82,7 @@ fn main() -> Result<(), String> {
KeyBinding::new("cmd-m", workspace::Minimize, None),
KeyBinding::new("cmd-n", workspace::NewSession, None),
KeyBinding::new("cmd-c", chat::CopySelection, Some("Transcript")),
+ KeyBinding::new("escape", chat::Interrupt, Some("Chat")),
// Every Enter chord but plain Enter starts a new line.
KeyBinding::new(
"ctrl-enter",
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org