Procházet zdrojové kódy

fix(cli): clear input field on Ctrl+C (#4728)

* fix(cli): clear input field on Ctrl+C

* Remove hooks

* Add changeset
marius-kilocode před 1 měsícem
rodič
revize
8ecb081d10

+ 5 - 0
.changeset/cli-ctrl-c-clear-input.md

@@ -0,0 +1,5 @@
+---
+"@kilocode/cli": patch
+---
+
+Clear input field when Ctrl+C is pressed

+ 36 - 0
cli/src/state/atoms/__tests__/keyboard.test.ts

@@ -1114,5 +1114,41 @@ describe("keypress atoms", () => {
 			expect(store.get(exitPromptVisibleAtom)).toBe(false)
 			expect(store.get(exitRequestCounterAtom)).toBe(1)
 		})
+
+		it("should clear text buffer when Ctrl+C is pressed", async () => {
+			// Type some text first
+			const chars = ["t", "e", "s", "t"]
+			for (const char of chars) {
+				const key: Key = {
+					name: char,
+					sequence: char,
+					ctrl: false,
+					meta: false,
+					shift: false,
+					paste: false,
+				}
+				store.set(keyboardHandlerAtom, key)
+			}
+
+			// Verify we have text in the buffer
+			expect(store.get(textBufferStringAtom)).toBe("test")
+
+			// Press Ctrl+C
+			const ctrlCKey: Key = {
+				name: "c",
+				sequence: "\u0003",
+				ctrl: true,
+				meta: false,
+				shift: false,
+				paste: false,
+			}
+			await store.set(keyboardHandlerAtom, ctrlCKey)
+
+			// Text buffer should be cleared
+			expect(store.get(textBufferStringAtom)).toBe("")
+
+			// Exit prompt should be visible
+			expect(store.get(exitPromptVisibleAtom)).toBe(true)
+		})
 	})
 })

+ 1 - 0
cli/src/state/atoms/keyboard.ts

@@ -910,6 +910,7 @@ function handleGlobalHotkeys(get: Getter, set: Setter, key: Key): boolean {
 		case "c":
 			if (key.ctrl) {
 				set(triggerExitConfirmationAtom)
+				set(clearTextBufferAtom)
 				return true
 			}
 			break