Skip to content

Commit f67afbc

Browse files
committed
fixing shortcut for composer
1 parent a0e3e5f commit f67afbc

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

src/ui/ink/AgentUI.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,19 @@ export function AgentUI({
235235
return;
236236
}
237237

238-
// Handle Ctrl+C - first warns, second exits
238+
// Handle Ctrl+C - clear input if non-empty, otherwise warn then exit
239239
if (key.ctrl && char === 'c') {
240+
const currentInput = textBufferRef.current.getText();
241+
242+
if (currentInput.length > 0) {
243+
// Clear the input on first Ctrl+C when there's text
244+
textBufferRef.current.setText('');
245+
syncInputFromBuffer();
246+
setCtrlCCount(0);
247+
return;
248+
}
249+
250+
// Input is empty - handle exit flow
240251
if (ctrlCCount === 0) {
241252
setCtrlCCount(1);
242253
onCtrlC();

tests/ui/ink/AgentUI.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { describe, expect, it } from 'vitest';
7+
import { describe, expect, it, vi } from 'vitest';
88
import type { Key as InkKey } from 'ink';
99
import { TextBuffer } from '../../../src/ui/textBuffer.js';
1010
import {
@@ -80,3 +80,52 @@ describe('AgentUI layout stability', () => {
8080
expect(getComposerHelpLine(true, '70% context left', '? shortcuts · / commands')).toBe(' ');
8181
});
8282
});
83+
84+
describe('AgentUI Ctrl+C behavior', () => {
85+
it('clears input when Ctrl+C is pressed with non-empty text', () => {
86+
const buffer = new TextBuffer(80, 10, 'hello world');
87+
const onCtrlC = vi.fn();
88+
89+
// Simulate the Ctrl+C handler logic from AgentUI
90+
const currentInput = buffer.getText();
91+
92+
if (currentInput.length > 0) {
93+
// Should clear the input
94+
buffer.setText('');
95+
onCtrlC();
96+
}
97+
98+
expect(buffer.getText()).toBe('');
99+
expect(onCtrlC).toHaveBeenCalled();
100+
});
101+
102+
it('does not trigger exit flow when Ctrl+C is pressed with non-empty text', () => {
103+
const buffer = new TextBuffer(80, 10, 'some typed text');
104+
let exitCalled = false;
105+
106+
// Simulate the Ctrl+C handler logic from AgentUI
107+
const currentInput = buffer.getText();
108+
109+
if (currentInput.length > 0) {
110+
// Should clear the input, NOT go to exit flow
111+
buffer.setText('');
112+
} else {
113+
// Exit flow only when input is empty
114+
exitCalled = true;
115+
}
116+
117+
expect(buffer.getText()).toBe('');
118+
expect(exitCalled).toBe(false);
119+
});
120+
121+
it('preserves multi-line content until Ctrl+C clears it', () => {
122+
const buffer = new TextBuffer(80, 10, 'line1\nline2\nline3');
123+
124+
expect(buffer.getText()).toBe('line1\nline2\nline3');
125+
126+
// Simulate Ctrl+C clearing
127+
buffer.setText('');
128+
129+
expect(buffer.getText()).toBe('');
130+
});
131+
});

0 commit comments

Comments
 (0)