Wrapping to the next line in mobile view

This commit is contained in:
2026-09-30 10:04:54 +03:30
parent e6fb5c3700
commit 7c4b24fad6
+24 -16
View File
@@ -329,25 +329,33 @@ async function confirmDeleteMessage(msg: ChatMessage) {
}
}
function isMobileComposer() {
return typeof window !== 'undefined' && window.matchMedia('(max-width: 900px)').matches;
}
function insertComposerNewline() {
const el = draftInputEl.value;
if (!el) {
draft.value += '\n';
return;
}
const start = el.selectionStart ?? draft.value.length;
const end = el.selectionEnd ?? start;
draft.value = draft.value.slice(0, start) + '\n' + draft.value.slice(end);
nextTick(() => {
const pos = start + 1;
el.focus();
el.setSelectionRange(pos, pos);
});
}
function onComposerKeydown(event: KeyboardEvent) {
if (event.key !== 'Enter') return;
// موبایل: Enter = خط بعد؛ ارسال فقط با دکمه ارسال
if (isMobileComposer()) return;
if (event.ctrlKey || event.metaKey) {
// Ctrl/Cmd+Enter → newline
event.preventDefault();
const el = draftInputEl.value;
if (!el) {
draft.value += '\n';
return;
}
const start = el.selectionStart ?? draft.value.length;
const end = el.selectionEnd ?? start;
const next = draft.value.slice(0, start) + '\n' + draft.value.slice(end);
draft.value = next;
nextTick(() => {
const pos = start + 1;
el.focus();
el.setSelectionRange(pos, pos);
});
insertComposerNewline();
return;
}
if (event.shiftKey) return;
@@ -1107,7 +1115,7 @@ onUnmounted(() => {
rows="1"
:placeholder="editingMessageId ? 'ویرایش پیام…' : 'پیام بنویسید…'"
autocomplete="off"
enterkeyhint="send"
enterkeyhint="enter"
:disabled="sending || recording"
@focus="emojiOpen = false"
@keydown="onComposerKeydown"