Skip to content

fix: add proper Shift+Enter and Ctrl+J newline handling (#871)#875

Merged
dgageot merged 1 commit intodocker:mainfrom
rockygeekz:fix/newline-shift-enter
Nov 22, 2025
Merged

fix: add proper Shift+Enter and Ctrl+J newline handling (#871)#875
dgageot merged 1 commit intodocker:mainfrom
rockygeekz:fix/newline-shift-enter

Conversation

@rockygeekz
Copy link
Copy Markdown
Contributor

Hey!
This PR adds the right behavior for Enter, Shift+Enter, and Ctrl+J as discussed in issue #871.

Enter now submits the message

Shift+Enter adds a newline (when the terminal actually sends that key)

Ctrl+J always adds a newline as a fallback on terminals that don’t support Shift+Enter

I tested this in a couple of environments:

Ubuntu terminal → Shift+Enter works and inserts a newline

WSL/Windows Terminal → Shift+Enter isn’t detected, but Ctrl+J works as expected

This follows the guidance you mentioned:
“use shift-enter when possible, and ctrl-j otherwise.”

If you want me to adjust anything or add more tests, I’m happy to update it!

@rockygeekz rockygeekz requested a review from a team as a code owner November 19, 2025 21:05
@rockygeekz rockygeekz force-pushed the fix/newline-shift-enter branch from 43cab7e to 7fe49fc Compare November 20, 2025 04:50
@dgageot
Copy link
Copy Markdown
Member

dgageot commented Nov 20, 2025

@rockygeekz could you tell the user which key stroke to use?

Screenshot 2025-11-20 at 08 30 54

@rockygeekz rockygeekz force-pushed the fix/newline-shift-enter branch from 7fe49fc to f250123 Compare November 20, 2025 08:15
@rockygeekz
Copy link
Copy Markdown
Contributor Author

@dgageot Behavior works as expected, and the UI now looks like this (see the image).
If you need any changes or adjustments, please feel free to let me know.

Screenshot 2025-11-20 134803

@rumpl
Copy link
Copy Markdown
Member

rumpl commented Nov 20, 2025

Just got time to look at this, we should do this differently, bubbletea has some things that can help us for this, it's weird and hidden but here's how it looks.

We should, in the tui.go (maybe?) listen to the event tea.KeyboardEnhancementsMsg and send it down to the editor, the editor can then check for the msg.Flags, if mgs.Flags is anything but 0 then we can set shift+enter, if not, we should set ctrl+j as the keys to add a new line.

We should set the keyboard shortcuts dynamically so that we always have only one shortcut for newlines at any time.

If you are on a mac you can test both cases easily: the default terminal doesn't support keyboard enhancements, while iterm does. Not sure how you would test this on a Windows machine...

@dgageot
Copy link
Copy Markdown
Member

dgageot commented Nov 22, 2025

@rumpl I'm going to merge this one and improve the implementation in another PR

@dgageot dgageot merged commit be4fa6d into docker:main Nov 22, 2025
5 checks passed
@rockygeekz
Copy link
Copy Markdown
Contributor Author

Hi @dgageot Thanks for merging! I wasn’t able to test the mac/iTerm side, but hope the contribution was helpful.

@benodiwal
Copy link
Copy Markdown
Contributor

Just got time to look at this, we should do this differently, bubbletea has some things that can help us for this, it's weird and hidden but here's how it looks.

We should, in the tui.go (maybe?) listen to the event tea.KeyboardEnhancementsMsg and send it down to the editor, the editor can then check for the msg.Flags, if mgs.Flags is anything but 0 then we can set shift+enter, if not, we should set ctrl+j as the keys to add a new line.

We should set the keyboard shortcuts dynamically so that we always have only one shortcut for newlines at any time.

If you are on a mac you can test both cases easily: the default terminal doesn't support keyboard enhancements, while iterm does. Not sure how you would test this on a Windows machine...

Hey @rumpl, can u give a read to my thoughts here #930 once. Thanks !!

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.

4 participants