Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-ctrl-c-compaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix Ctrl-C during compaction so it clears a pending editor draft first instead of cancelling immediately.
15 changes: 11 additions & 4 deletions apps/kimi-code/src/tui/controllers/editor-keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export class EditorKeyboardController {

if (host.state.appState.isCompacting) {
this.clearPendingExit();

if (this.clearEditorTextIfPresent()) return;

this.cancelCurrentCompaction();
return;
}
Expand All @@ -88,10 +91,7 @@ export class EditorKeyboardController {
if (host.state.appState.streamingPhase !== 'idle') {
this.clearPendingExit();

if (editor.getText().length > 0) {
editor.setText('');
return;
}
if (this.clearEditorTextIfPresent()) return;

this.cancelCurrentStream();
return;
Expand Down Expand Up @@ -254,6 +254,13 @@ export class EditorKeyboardController {
this.host.state.ui.requestRender();
}

private clearEditorTextIfPresent(): boolean {
const editor = this.host.state.editor;
if (editor.getText().length === 0) return false;
editor.setText('');
return true;
}

private cancelCurrentStream(): void {
void this.host.session?.cancel();
}
Expand Down
24 changes: 24 additions & 0 deletions apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,30 @@ command = "vim"
expect(session.cancelCompaction).toHaveBeenCalledTimes(1);
});

it('clears editor text before cancelling compaction on Ctrl-C', async () => {
const { driver, session } = await makeDriver();
driver.sessionEventHandler.handleEvent(
{
type: 'compaction.started',
agentId: 'main',
sessionId: 'ses-1',
trigger: 'manual',
} as Event,
vi.fn(),
);
driver.state.editor.setText('draft while compacting');

driver.state.editor.onCtrlC?.();

expect(driver.state.editor.getText()).toBe('');
expect(session.cancelCompaction).not.toHaveBeenCalled();
expect(driver.state.appState.isCompacting).toBe(true);

driver.state.editor.onCtrlC?.();

expect(session.cancelCompaction).toHaveBeenCalledTimes(1);
});

it('dispatches the next queued message after compaction is cancelled', async () => {
vi.useFakeTimers();
try {
Expand Down
Loading