输入框支持换行:Enter 仍为发送,Ctrl/⌘/⌥+Enter(及 Shift+Enter)在光标处插入换行并联动高度自适应;新增 IME isComposing 防护避免中文候选回车误发送;.msg.me .msg-bubble 加 white-space:pre-wrap 使发送后的多行消息保留换行
This commit is contained in:
@@ -110,7 +110,7 @@ body {
|
|||||||
word-break: break-word; overflow-wrap: break-word; font-size: 14.5px;
|
word-break: break-word; overflow-wrap: break-word; font-size: 14.5px;
|
||||||
background: #fff; box-shadow: 0 1px 3px rgba(30,40,90,0.07);
|
background: #fff; box-shadow: 0 1px 3px rgba(30,40,90,0.07);
|
||||||
}
|
}
|
||||||
.msg.me .msg-bubble { background: #d7e7ff; border-bottom-right-radius: 4px; }
|
.msg.me .msg-bubble { background: #d7e7ff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
|
||||||
.msg.other .msg-bubble { border-bottom-left-radius: 4px; }
|
.msg.other .msg-bubble { border-bottom-left-radius: 4px; }
|
||||||
.msg-bubble pre {
|
.msg-bubble pre {
|
||||||
background: #f0f2f6; padding: 8px 10px; border-radius: 8px;
|
background: #f0f2f6; padding: 8px 10px; border-radius: 8px;
|
||||||
|
|||||||
@@ -452,10 +452,21 @@ document.addEventListener('input', e => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener('keydown', 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();
|
||||||
|
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();
|
e.preventDefault();
|
||||||
ui.send();
|
ui.send();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------- 启动 ----------
|
// ---------- 启动 ----------
|
||||||
|
|||||||
Reference in New Issue
Block a user