Skip to content

fix(vscode): restore undo and redo in the chat input - #14200

Merged
marius-kilocode merged 5 commits into
mainfrom
bolder-order
Sep 16, 2026
Merged

marius-kilocode merged 5 commits into
mainfrom
bolder-order

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Undo and redo did nothing in the Kilo chat input. After typing, Cmd+Z and Cmd+Shift+Z (Ctrl+Z and Ctrl+Y on Windows and Linux) left the text unchanged, while Edit > Undo from the macOS menu bar worked. The same gap existed in the Agent Manager New Worktree prompt.

This is the unfixed half of #13724. The earlier guard stopped the shortcut from leaking into an active markdown editor, but nothing performed the undo in the webview, so the reported "does not undo/redo the typed text" symptom remained.

Fixes #14191

Why This Change Was Made

VS Code's webview preload intercepts Ctrl/Cmd+Z and Ctrl+Y and forwards them to the workbench, so a webview cannot rely on the key event reaching an editor. The existing guard called stopPropagation() to block that forwarding, which stops the leak but also removes the only path that would have performed the edit.

A keypress inside a VS Code webview has no native undo default action on macOS. With the forwarding blocked, the event arrived clean and died, which is why the code read as correct while the feature stayed broken.

The fix performs the edit explicitly with document.execCommand("undo" | "redo"), which operates on the same native undo stack real typing builds. It also matches keyCode 90 and 89 in addition to e.key, mirroring how VS Code's preload detects the shortcut. On a non-Latin layout (for example Hebrew) Cmd+Z reports e.key === "ז" with keyCode === 90, so the old e.key-only check missed it and the leak returned.

The New Worktree prompt had its own textarea with no undo guard at all, so its handling is now shared through prompt-input-utils.ts. The existing "undo the last Enhance" behavior keeps priority and is unchanged.

User Impact

Undo and redo now work in the sidebar chat input, the Agent Manager chat composer, and the New Worktree prompt. This includes Ctrl+Y and Cmd+Shift+Z for redo, and non-Latin keyboard layouts.

Evidence

Verified in an isolated VS Code dev host with real trusted key events, before and after the change:

Scenario (macOS) Before After
hello world then Ctrl+Z unchanged "", Send disabled
then Ctrl+Y unchanged hello world, Send enabled
Cmd+Z input events not representative in the harness exactly one historyUndo
Cmd+Shift+Z input events not representative in the harness exactly one historyRedo
New Worktree prompt Ctrl+Z / Ctrl+Y unchanged "" then restored
Agent Manager chat Ctrl+Z / Ctrl+Shift+Z unchanged "" then restored
Keydown reaching the frame window listener leaks 0 events

Playwright maps Meta+KeyZ to Chromium's native undo: editing command, which a real VS Code keypress never carries, so Meta presses are not a faithful before-state in the harness. Control+z and Control+y have no such mapping and arrive as plain trusted key events, so those were used for the before and after comparison. The handler treats ctrlKey and metaKey identically.

bun run compile (types, webview types, lint, bundle), bun run knip, and the changeset are included.

VS Code's webview preload intercepts Ctrl/Cmd+Z and Ctrl+Y and forwards
them to the workbench, so the prompt input stopped propagation but never
performed the edit. A webview keypress has no native undo default action
on macOS, so the undo stack stayed untouched and the shortcuts did
nothing.

Perform the edit with document.execCommand on the same native undo stack
real typing builds, and match keyCode like VS Code does so non-Latin
keyboard layouts no longer leak the key back to the workbench.

The Agent Manager New Worktree prompt had the same gap with no guard at
all; it now shares the same helper through prompt-input-utils.
@kilo-code-bot

kilo-code-bot Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • .changeset/chat-input-undo-redo.md
  • packages/kilo-vscode/tests/prompt-undo.spec.ts
  • packages/kilo-vscode/tests/unit/prompt-input-utils.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/NewWorktreeDialog.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/prompt-input-utils.ts
Previous Review Summary (commit 78a4d93)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 78a4d93)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/prompt-input-utils.ts 42 New exported undoKey helper has no unit coverage while every other export in the module is tested
Files Reviewed (4 files)
  • .changeset/chat-input-undo-redo.md - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/NewWorktreeDialog.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/src/components/chat/prompt-input-utils.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

The specs asserted that the webview never cancels the host default for
Ctrl/Cmd+Z, Ctrl+Shift+Z, and Ctrl+Y, which is the behavior that left
undo broken inside VS Code. The prompt now cancels the default and
performs the edit itself, so the expectations move to prevented: true.

Add coverage for the keyCode match, which keeps non-Latin layouts in
lockstep with VS Code's own detection.
Exercises the Ctrl/Cmd+z undo mapping, the Shift+z and y redo
mappings, the keyCode fallback that keeps non-Latin layouts in
lockstep with VS Code, and the chords that must keep forwarding.
# Conflicts:
#	packages/kilo-vscode/tests/unit/prompt-input-utils.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VSCode] Mac 26.6.2 chat keyboard input undo/redo not working (unfixed half of #13724)

2 participants