Skip to content

feat(shell): add Shift+Enter as newline shortcut alongside Ctrl-J and Alt-Enter#2302

Open
ktwu01 wants to merge 1 commit into
MoonshotAI:mainfrom
ktwu01:feat/shift-enter-newline
Open

feat(shell): add Shift+Enter as newline shortcut alongside Ctrl-J and Alt-Enter#2302
ktwu01 wants to merge 1 commit into
MoonshotAI:mainfrom
ktwu01:feat/shift-enter-newline

Conversation

@ktwu01
Copy link
Copy Markdown

@ktwu01 ktwu01 commented May 15, 2026

Summary

  • Adds s-enter (Shift+Enter) to the newline keybinding in src/kimi_cli/ui/shell/prompt.py, alongside the existing escape+enter (Alt-Enter) and c-j (Ctrl-J) bindings
  • Updates the bottom toolbar hint from ctrl-j: newline to shift-enter / ctrl-j: newline
  • Updates English and Chinese docs (keyboard.md, interaction.md) to list Shift+Enter as the primary newline shortcut

No breaking changes. Ctrl-J and Alt-Enter continue to work exactly as before.

Closes #2254

Test plan

  • Press Shift+Enter in the interactive prompt: a newline is inserted, message is NOT submitted
  • Press Ctrl-J: still inserts a newline (backward compat)
  • Press Alt-Enter: still inserts a newline (backward compat)
  • Bottom toolbar tip shows shift-enter / ctrl-j: newline
  • docs/en/reference/keyboard.md and docs/zh/reference/keyboard.md list Shift-Enter in the shortcuts table

🤖 Generated with Claude Code


Open in Devin Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review


@_kb.add("escape", "enter", eager=True)
@_kb.add("c-j", eager=True)
@_kb.add("s-enter", eager=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 s-enter is not a valid prompt_toolkit key name, crashing CustomPromptSession.__init__

_kb.add("s-enter", eager=True) raises ValueError: Invalid key: s-enter at call time because s-enter does not exist in prompt_toolkit's ALL_KEYS (verified on both 3.0.28 and the pinned 3.0.52). Because Python evaluates stacked decorators bottom-up, this error fires before the c-j and escape+enter decorators above it are applied, so all three newline bindings fail to register and the CustomPromptSession.__init__ crashes entirely. This means the interactive shell UI cannot start at all.

Reproduction confirming the issue on prompt_toolkit 3.0.52
from prompt_toolkit.key_binding import KeyBindings
kb = KeyBindings()

try:
    @kb.add('escape', 'enter', eager=True)
    @kb.add('c-j', eager=True)
    @kb.add('s-enter', eager=True)
    def handler(event):
        pass
except Exception as e:
    print(f'Error: {e}')  # ValueError: Invalid key: s-enter

print(len(kb.bindings))  # 0 — none of the three bindings were registered

Shift+Enter is indistinguishable from Enter in most terminals because they both send \r. Modern terminals supporting the Kitty keyboard protocol can distinguish them, but prompt_toolkit does not expose a s-enter key. A different approach is needed (e.g., handling via a VT100 escape sequence or the Kitty protocol directly).

Prompt for agents
The key name `s-enter` is not recognized by prompt_toolkit (tested on 3.0.52, the pinned version). The `_kb.add("s-enter", eager=True)` call at `src/kimi_cli/ui/shell/prompt.py:1324` raises ValueError immediately, which also prevents the Ctrl-J and Alt-Enter bindings from being registered (since decorators are evaluated bottom-up), and crashes the entire CustomPromptSession.__init__.

Shift+Enter is fundamentally indistinguishable from Enter in classic terminal protocols (both send CR). Only terminals implementing the Kitty keyboard protocol can differentiate them, and prompt_toolkit has no built-in support for this.

Possible approaches:
1. Remove the `s-enter` binding entirely and keep only `c-j` and `escape+enter` (Alt-Enter) as before, updating docs accordingly.
2. If Kitty protocol support is desired, handle the raw escape sequence `\x1b[13;2u` (Shift+Enter in Kitty protocol) by adding it to prompt_toolkit's VT100 input parser, or use a custom key binding approach that works with terminals that report this sequence.
3. At minimum, the `@_kb.add("s-enter", eager=True)` line must be separated from the other two decorators (or wrapped in a try/except) so that its failure does not break Ctrl-J and Alt-Enter.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b456c5fdc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


@_kb.add("escape", "enter", eager=True)
@_kb.add("c-j", eager=True)
@_kb.add("s-enter", eager=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Replace unsupported Shift-Enter key spec

Using @_kb.add("s-enter", eager=True) introduces a startup-breaking binding because prompt-toolkit==3.0.52 does not define s-enter as a valid special key (it only supports s-tab and a limited set of other s-* keys), and KeyBindings.add() validates keys eagerly via _parse_key, which raises ValueError("Invalid key: s-enter") for multi-character unknown keys. As a result, constructing CustomPromptSession fails before the shell prompt can run.

Useful? React with 👍 / 👎.

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.

feat(shell): support Shift+Enter for inserting newlines

1 participant