-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Description
I noticed that the shift+enter keybinding, which is supposed to insert a newline in the input field, doesn’t seem to work. However, the alternative keybinding ctrl+j works fine for the same action.
Expected Behavior
When I press shift+enter, it should insert a newline in the input field.
Observed Behavior
- Pressing
shift+enter- Does nothing when the input is blank
- Send the message when the input is not blank
- On the other hand,
ctrl+jworks as expected and inserts a newline.
Steps to Reproduce
- Open OpenCode.
- Focus on an input field.
- Press
shift+enterto try inserting a newline. - Notice that nothing happens.
Environment
- Platform: macOS M2 (version 14.6.1)
- Terminal: tested on Terminal and Warp
- Version: tested on dev branch
Analysis by Qwen3 Coder
That's the key! Looking at the editor code, I can see what's happening:
- When a key event occurs, the editor first checks if
msg.Text != ""(line 126)- If there's text in the message, it directly passes the message to the textarea's Update method (line 128)
ctrl+jis interpreted by the terminal as a newline character (\n), so msg.Text contains "\n"- This gets passed directly to the textarea, which inserts it as a newline
However, shift+enter is not interpreted as text by the terminal - it's sent as a special key event. Since there's no
msg.Textforshift+enter, the code doesn't take the early return path, and instead continues to process the key event through the rest of the switch statement.The issue is that
shift+enteris not being handled specifically in the editor's key processing logic. Let me look at where commands are actually executed:
qwen/qwen3-coder:free (09:00 PM)
Now I understand the issue! Looking at the code flow:
- In the TUI's Update method, key events are first checked against commands using
a.app.Commands.Matches(msg, a.app.IsLeaderSequence)(line 304 in tui.go)- If a command matches, it gets executed via
commands.ExecuteCommandsMsg(matches)(line 310)- The InputNewlineCommand is configured with keybindings for "shift+enter" and "ctrl+j" (line 299 in command.go)
The problem is that when
shift+enteris pressed:
- It matches the
InputNewlineCommand- The command gets executed
- But there's likely no handler for InputNewlineCommand that actually calls the editor's
Newline()methodLet me check where commands are actually executed:
qwen/qwen3-coder:free (09:00 PM)