Textarea: Ctrl/Cmd+Enter inserts a newline before emitting PressEnter { secondary: true }

Open Beginner friendly
#3,871 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
frontend

Research direction

Start with enter in crates/base/src/input/base/state.rs and trace how action.secondary and is_code_editor() are handled. Check the input tests for multiline Enter behavior, then add coverage for Ctrl/Cmd+Enter in a regular textarea and a code editor. Done means the regular textarea keeps its text unchanged while emitting the secondary PressEnter event, and the code editor retains its existing behavior.

Written by the indexing model from the issue text.

Description

Description

In a multi-line field, a secondary Enter (Ctrl+Enter, Cmd+Enter on macOS) inserts a newline at the caret and then emits InputEvent::PressEnter { secondary: true }. enter in crates/base/src/input/base/state.rs decides from submit_on_enter and Shift only:

let insert_newline = self.is_multi_line() && (!self.submit_on_enter || action.shift);

Ctrl/Cmd+Enter is the usual submit gesture of a chat or comment field. When the application submits and clears the field, the extra line goes unseen. When it does not submit (the message cannot be sent yet, so the text is kept), a stray empty line is left in the text, before the caret.

Environment

  • GPUI: gpui-pre 0.3.11
  • GPUI Component: 0.9.0 (gpui-base 0.9.0); the same logic on main (checked at 7cace79d)
  • Platform: Ubuntu 24.04.5; the code path is platform independent

Steps to Reproduce

  1. A Textarea (InputState::new(window, cx).multi_line(true)), subscribe to InputEvent::PressEnter, and on secondary: true do nothing (do not clear the field).
  2. Type "hello", press Home, then Ctrl+Enter.

Expected

The text stays "hello"; the event says the person asked to submit.

Actual

The text becomes "\nhello".

Suggested fix

A secondary Enter in a field that is not a code editor inserts nothing; the event is emitted as before. A code editor keeps its own meaning for Ctrl+Enter.

let secondary_submit = action.secondary && !self.is_code_editor();
let insert_newline =
    self.is_multi_line() && !secondary_submit && (!self.submit_on_enter || action.shift);
Dominant language
Rust
Stars
20k
Forks
1.2k
Avg merge
1d 3h
Merged PRs (30d)
276

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from longbridge/gpui-kit

All issues in longbridge/gpui-kit

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.