diff --git a/static/js/conversations.js b/static/js/conversations.js index b5f1d00..dabebab 100644 --- a/static/js/conversations.js +++ b/static/js/conversations.js @@ -1225,24 +1225,24 @@ }, }); - // Enter = send: let Quill process keystroke first (15ms), then capture+clear+send - state.quill.root.addEventListener('keydown', function (e) { - if (e.key === 'Enter' && !e.shiftKey) { - e.preventDefault(); - e.stopImmediatePropagation(); - if (state._pendingSend) return; // Already scheduled - state._pendingSend = true; - setTimeout(function() { - state._pendingSend = false; - var html = state.quill.root.innerHTML; - var text = state.quill.getText().trim(); - if (text) { - state.quill.setText(''); - Composer.sendContent(html, text); - } - }, 15); + // Enter = send: prepend our handler BEFORE Quill's default Enter handlers + // Quill stores handlers in keyboard.bindings keyed by keyCode + var enterBindings = state.quill.keyboard.bindings[13] || []; + // Insert our handler at the BEGINNING so it runs first + enterBindings.unshift({ + key: 13, + shiftKey: false, + handler: function() { + var html = state.quill.root.innerHTML; + var text = state.quill.getText().trim(); + if (text) { + state.quill.setText(''); + Composer.sendContent(html, text); + } + return false; // Block Quill's default Enter (newline insertion) } - }, true); + }); + state.quill.keyboard.bindings[13] = enterBindings; // Typing indicator state.quill.on('text-change', function () {