Wrapping to the next line in mobile view
This commit is contained in:
@@ -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) {
|
function onComposerKeydown(event: KeyboardEvent) {
|
||||||
if (event.key !== 'Enter') return;
|
if (event.key !== 'Enter') return;
|
||||||
|
// موبایل: Enter = خط بعد؛ ارسال فقط با دکمه ارسال
|
||||||
|
if (isMobileComposer()) return;
|
||||||
if (event.ctrlKey || event.metaKey) {
|
if (event.ctrlKey || event.metaKey) {
|
||||||
// Ctrl/Cmd+Enter → newline
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const el = draftInputEl.value;
|
insertComposerNewline();
|
||||||
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);
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.shiftKey) return;
|
if (event.shiftKey) return;
|
||||||
@@ -1107,7 +1115,7 @@ onUnmounted(() => {
|
|||||||
rows="1"
|
rows="1"
|
||||||
:placeholder="editingMessageId ? 'ویرایش پیام…' : 'پیام بنویسید…'"
|
:placeholder="editingMessageId ? 'ویرایش پیام…' : 'پیام بنویسید…'"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
enterkeyhint="send"
|
enterkeyhint="enter"
|
||||||
:disabled="sending || recording"
|
:disabled="sending || recording"
|
||||||
@focus="emojiOpen = false"
|
@focus="emojiOpen = false"
|
||||||
@keydown="onComposerKeydown"
|
@keydown="onComposerKeydown"
|
||||||
|
|||||||
Reference in New Issue
Block a user