mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-07-29 04:52:53 +02:00
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:
@@ -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
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user