feat(chat): require explicit send button on touch devices

Enter on a phone's virtual keyboard now inserts a newline instead of
sending, in both group chat and DM. Detected via the pointer:coarse
media query - no user-facing setting, since accidental sends from a
mistapped Enter were the actual complaint. Desktop keeps Enter-to-send.
This commit is contained in:
MarekWo
2026-06-29 09:31:50 +02:00
parent 7be3e26161
commit ca4c77da36
3 changed files with 17 additions and 4 deletions
+4 -2
View File
@@ -636,9 +636,11 @@ function setupEventListeners() {
sendMessage();
});
// Handle Enter key (send) vs Shift+Enter (new line)
// Handle Enter key (send) vs Shift+Enter (new line) - desktop only.
// Touch devices send via the button so an accidental Enter on the virtual
// keyboard doesn't fire a half-typed message.
input.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
if (e.key === 'Enter' && !e.shiftKey && !isTouchPrimaryDevice()) {
e.preventDefault();
sendMessage();
}
+3 -2
View File
@@ -437,9 +437,10 @@ function setupEventListeners() {
if (input) {
input.addEventListener('input', updateCharCounter);
// Enter key to send
// Enter key to send (desktop only - touch devices send via the button
// so an accidental Enter on the virtual keyboard doesn't fire a half-typed message)
input.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
if (e.key === 'Enter' && !e.shiftKey && !isTouchPrimaryDevice()) {
e.preventDefault();
sendMessage();
}
+10
View File
@@ -3,6 +3,16 @@
* Handles mention badges, URL links, and image previews
*/
/**
* Detect whether the primary input is touch-based (phones/tablets), as opposed
* to a device with a precise pointer (mouse/trackpad). Used to decide whether
* Enter should send a message or just insert a newline.
* @returns {boolean}
*/
function isTouchPrimaryDevice() {
return window.matchMedia('(pointer: coarse)').matches;
}
/**
* Process message content to handle mentions, URLs, and images
* @param {string} content - Raw message content