Skip to content

feat: Add prompt undo and redo shortcuts#59

Merged
qorzj merged 1 commit into
lessweb:mainfrom
Lellansin:feat/prompt-undo-redo
May 14, 2026
Merged

feat: Add prompt undo and redo shortcuts#59
qorzj merged 1 commit into
lessweb:mainfrom
Lellansin:feat/prompt-undo-redo

Conversation

@Lellansin
Copy link
Copy Markdown
Contributor

变更内容

  • 为 Prompt 输入框增加 Ctrl+- undo 和 Ctrl+Shift+- redo 快捷键。
  • 解析终端 modifyOtherKeys 下的 Ctrl+- / Ctrl+Shift+- 序列,并兼容 raw 0x1F redo fallback。
  • 将 Prompt undo/redo 栈逻辑拆成独立模块,提交、取消输入、执行 slash 命令或消费 slash token 后会清空历史,避免恢复已处理的命令文本。
  • 补充快捷键解析和 undo/redo 栈语义的单元测试。

背景

Prompt 输入目前支持多种编辑快捷键,但缺少常见的撤销和重做能力。终端在不同按键模式下对 Ctrl+- / Ctrl+Shift+- 的上报不同,本次改动在已有 extended key reporting 基础上兼容常见序列,并保持标准 redo 语义:新编辑会清空 redo 历史。

验证

  • npm test -- --test-reporter=spec
  • npm run typecheck
  • npm run lint
  • npm run format:check
  • git diff --check main...HEAD
  • codex review --base main

Adds Emacs-style undo/redo for the prompt input buffer:

- ctrl+- (undo): reverses text changes one step at a time, all the
  way back to the initial empty buffer. Uses an undo stack capped
  at 1000 entries.
- ctrl+shift+- (redo): restores undone changes one step at a time.
  New edits clear the redo history.
- Pure cursor movement does not create undo entries.
- Terminal input parsing handles modifyOtherKeys CSI sequences:
  \u001B[45;5u and \u001B[27;5;45~ for undo, \u001B[45;6u
  and \u001B[27;6;45~ for redo, plus raw 0x1F as redo fallback.
@qorzj qorzj merged commit 2a615d1 into lessweb:main May 14, 2026
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.

2 participants