忘记改了

This commit is contained in:
shuaiplus committed 2025-05-21 01:38:20 +08:00
1 parent d5fdfc2728
commit 39fa715703
2 files changed
+46 -3

No files matched your search

+42
View File
@@ -328,6 +328,45 @@ export function autoGrowInput() {
input.style.height = input.scrollHeight + 'px';
}
/**
* 处理粘贴事件,确保粘贴为纯文本
* @param {HTMLElement} element 绑定处理的元素
*/
function handlePasteAsPlainText(element) {
if (!element) return;
on(element, 'paste', function(e) {
// 阻止默认粘贴行为
e.preventDefault();
// 获取纯文本
let text = '';
if (e.clipboardData || window.clipboardData) {
text = (e.clipboardData || window.clipboardData).getData('text/plain');
}
// 使用document.execCommand插入纯文本
if (document.queryCommandSupported('insertText')) {
document.execCommand('insertText', false, text);
} else {
// 回退方法:直接插入文本节点
const selection = window.getSelection();
if (selection.rangeCount) {
const range = selection.getRangeAt(0);
range.deleteContents();
const textNode = document.createTextNode(text);
range.insertNode(textNode);
// 将光标移动到插入的文本后面
range.setStartAfter(textNode);
range.setEndAfter(textNode);
selection.removeAllRanges();
selection.addRange(range);
}
}
});
}
/**
* 设置输入框占位符逻辑
*/
@@ -352,6 +391,9 @@ export function setupInputPlaceholder() {
on(input, 'blur', checkEmpty);
on(input, 'focus', checkEmpty);
// 添加粘贴纯文本处理
handlePasteAsPlainText(input);
// 初始化
checkEmpty();
autoGrowInput();
+4 -3
View File
@@ -408,7 +408,6 @@ body {
max-width: 100%;
color: #222;
border-bottom-left-radius: 0px;
margin-left: 0px;
padding: 1px 40px 5px 10px;
}
@@ -628,11 +627,13 @@ body {
color: #222;
width: 100%;
overflow-y: auto !important;
display: flex;
align-items: center;
display: block; /* 改为block而不是flex,更好地处理换行 */
/* 允许多行自动扩展高度 */
white-space: pre-wrap;
word-break: break-word;
word-wrap: break-word; /* 确保长单词也能换行 */
overflow-wrap: break-word; /* 现代浏览器的换行支持 */
max-width: 100%; /* 确保不超出容器 */
}
.input-field-placeholder {
position: absolute;