mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 13:55:19 +00:00
refac
This commit is contained in:
parent
e1386fe80b
commit
5eb26fe7ab
1 changed files with 21 additions and 5 deletions
|
|
@ -1105,14 +1105,30 @@
|
||||||
handlePaste: (view, event) => {
|
handlePaste: (view, event) => {
|
||||||
// Force plain-text pasting when richText === false
|
// Force plain-text pasting when richText === false
|
||||||
if (!richText) {
|
if (!richText) {
|
||||||
const text = (event.clipboardData?.getData('text/plain') ?? '').replace(/\r\n/g, '\n');
|
|
||||||
// swallow HTML completely
|
// swallow HTML completely
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// Insert as pure text (no HTML parsing)
|
|
||||||
const { state, dispatch } = view;
|
const { state, dispatch } = view;
|
||||||
const { from, to } = state.selection;
|
|
||||||
dispatch(state.tr.insertText(text, from, to).scrollIntoView());
|
const plainText = (event.clipboardData?.getData('text/plain') ?? '').replace(
|
||||||
|
/\r\n/g,
|
||||||
|
'\n'
|
||||||
|
);
|
||||||
|
|
||||||
|
const lines = plainText.split('\n');
|
||||||
|
const nodes = [];
|
||||||
|
|
||||||
|
lines.forEach((line, index) => {
|
||||||
|
if (index > 0) {
|
||||||
|
nodes.push(state.schema.nodes.hardBreak.create());
|
||||||
|
}
|
||||||
|
if (line.length > 0) {
|
||||||
|
nodes.push(state.schema.text(line));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const fragment = Fragment.fromArray(nodes);
|
||||||
|
dispatch(state.tr.replaceSelectionWith(fragment, false).scrollIntoView());
|
||||||
|
|
||||||
return true; // handled
|
return true; // handled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue