Skip to content

shift+enter keybinding not working #1505

@bluenex

Description

@bluenex

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+j works as expected and inserts a newline.

Steps to Reproduce

  1. Open OpenCode.
  2. Focus on an input field.
  3. Press shift+enter to try inserting a newline.
  4. 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:

  1. When a key event occurs, the editor first checks if msg.Text != "" (line 126)
  2. If there's text in the message, it directly passes the message to the textarea's Update method (line 128)
  3. ctrl+j is interpreted by the terminal as a newline character (\n), so msg.Text contains "\n"
  4. 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.Text for shift+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+enter is 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:

  1. 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)
  2. If a command matches, it gets executed via commands.ExecuteCommandsMsg(matches) (line 310)
  3. The InputNewlineCommand is configured with keybindings for "shift+enter" and "ctrl+j" (line 299 in command.go)

The problem is that when shift+enter is pressed:

  1. It matches the InputNewlineCommand
  2. The command gets executed
  3. But there's likely no handler for InputNewlineCommand that actually calls the editor's Newline() method

Let me check where commands are actually executed:
qwen/qwen3-coder:free (09:00 PM)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions