Skip to content

Send message using Enter on physical keyboard - #450

Open
RobertoTired wants to merge 3 commits into
GrapheneOS:mainfrom
RobertoTired:main
Open

RobertoTired wants to merge 3 commits into
GrapheneOS:mainfrom
RobertoTired:main

Conversation

@RobertoTired

Copy link
Copy Markdown

Allow sending of message using Enter key on physical keyboard. A parameter toggle has been added to switch between 'Enter to send / Enter + Shift for multiline' and 'Enter for multiline / Ctrl + Enter to send'.

  • AI has been used to generate translation for all languages except English and French, and it help me creating the unit test.
  • I have added a parameter to the top level parameter screen, I can move it where you want.
  • Tested on emulator and also on my physical Pixel 8, both in desktop mode with physical usb keyboard and in regular mode with soft keyboard.
  • If this PR is approved, I will try to fix also small anoying bugs when used in desktop mode (for example using arrow in text field may get the focus out of the text field).
  • Using Shift Enter or Ctrl Enter seems to be a "standard" on other messaging application (Signal and Teams for example).
  • I am quite new in android development (but not in Java), feel free to ask me to change anything (or remove it :))
    Thanks

Allow sending of message using Enter key on physical keyboard. A parameter toggle has been added to
switch between 'Enter to send / Enter + Shift for multiline' and 'Enter for multiline / Ctrl +
Enter to send'.
@RobertoTired

Copy link
Copy Markdown
Author

Not sure how to fix the Instrumented tests (Android 17 x86_64) issue... I run ./gradlew :app:connectedDebugAndroidTest with a local emulator and I got no issue

@RankoR

RankoR commented Oct 28, 2026

Copy link
Copy Markdown
Member

It fails because CI emu has 320x640 screen with 160dpi.

@RankoR RankoR left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please also:

  • Squash commits into a single commit
  • Remove new localized strings for all languages except English and Russian.

Feature tests coverage is incomplete:

  • MessageComposeBarInputTypeTest only tests with the setting off. Nothing covers setting on + Enter sends, setting on + Shift+Enter inserts a newline, or a soft-keyboard Enter not sending.
  • AppSettingsRepositoryImplTest.kt makes SEND_ON_ENTER return true, but never asserts result.sendOnEnterEnabled and doesn't include that read in its verify block
  • setBooleanPref_writesEveryApplicationBooleanPreferenceKey covers five prefs and skips SEND_ON_ENTER.
  • AppSettingsUiStateMapperImplTest only adds sendOnEnterEnabled = false, which is the default, so the mapping isn't really checked.

}
}

private fun EditText.setupKeyboardSendHandler(onImeSend: State<(() -> Unit)?>) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Enter from a soft keyboard counts as "physical keyboard" and sends the SMS. Reject events where event.flags and KeyEvent.FLAG_SOFT_KEYBOARD != 0, and add a test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, holding Enter can send more than once. Add event.repeatCount == 0.

keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER
if (isPhysicalKeyboard && isEnterKey && event.action == KeyEvent.ACTION_DOWN) {
val ctx = view.context
val prefs = ctx.getSharedPreferences(

@RankoR RankoR Oct 28, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

View must not read shared preferences.

Comment thread res/values/strings.xml
<string name="in_conversation_sound_pref_title">In-conversation message sounds</string>
<string name="in_conversation_sound_pref_summary">Play a quiet sound for a message that arrives in the conversation you are viewing. Muted and snoozed conversations stay silent.</string>
<string name="send_on_enter_pref_title">Send on Enter on physical keyboard</string>
<string name="send_on_enter_pref_summary">Send a message when pressing Enter on a physical keyboard. Use Shift + Enter for a new line. Ctrl + Enter always send the message</string>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be Ctrl + Enter always sends the message I think

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.

2 participants