输入框支持换行:Enter 仍为发送,Ctrl/⌘/⌥+Enter(及 Shift+Enter)在光标处插入换行并联动高度自适应;新增 IME isComposing 防护避免中文候选回车误发送;.msg.me .msg-bubble 加 white-space:pre-wrap 使发送后的多行消息保留换行

This commit is contained in:
2026-08-31 14:38:27 +08:00
parent 0d2e820118
commit d4cf407cd1
2 changed files with 14 additions and 3 deletions
+13 -2
View File
@@ -452,10 +452,21 @@ document.addEventListener('input', e => {
}
});
document.addEventListener('keydown', e => {
if (e.target.id === 'msg-input' && e.key === 'Enter' && !e.shiftKey) {
if (e.target.id !== 'msg-input' || e.key !== 'Enter') return;
if (e.isComposing) return; // 中文输入法候选中,回车不拦截
// Ctrl/⌘/⌥ + Enter(或 Shift + Enter)→ 插入换行
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) {
e.preventDefault();
ui.send();
const ta = e.target;
const s = ta.selectionStart;
ta.value = ta.value.slice(0, s) + '\n' + ta.value.slice(ta.selectionEnd);
ta.selectionStart = ta.selectionEnd = s + 1;
ta.style.height = 'auto';
ta.style.height = Math.min(ta.scrollHeight, 120) + 'px';
return;
}
e.preventDefault();
ui.send();
});
// ---------- 启动 ----------