titap: use default action when paste

This commit is contained in:
fantasticit 2022-09-16 19:47:10 +08:00
parent d967fc72f7
commit a197b47ec5
1 changed files with 3 additions and 7 deletions

View File

@ -154,7 +154,7 @@ export const Paste = Extension.create<IPasteOptions>({
return true; return true;
} }
// FIXME:各家 office 套件标准不一样,是否需要做成用户自行选择粘贴 html 或者 图片? // TODO:各家 office 套件标准不一样,是否需要做成用户自行选择粘贴 html 或者 图片?
if (html?.includes('urn:schemas-microsoft-com:office') || html?.includes('</table>')) { if (html?.includes('urn:schemas-microsoft-com:office') || html?.includes('</table>')) {
const doc = htmlToProsemirror({ const doc = htmlToProsemirror({
schema: editor.schema, schema: editor.schema,
@ -212,7 +212,7 @@ export const Paste = Extension.create<IPasteOptions>({
event.preventDefault(); event.preventDefault();
const { tr } = view.state; const { tr } = view.state;
tr.replaceSelectionWith(view.state.schema.nodes.codeBlock.create({ language: pasteCodeLanguage })); tr.replaceSelectionWith(view.state.schema.nodes.codeBlock.create({ language: pasteCodeLanguage }));
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2)))); tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 1))));
tr.insertText(text.replace(/\r\n?/g, '\n')); tr.insertText(text.replace(/\r\n?/g, '\n'));
tr.setMeta('paste', true); tr.setMeta('paste', true);
view.dispatch(tr); view.dispatch(tr);
@ -220,7 +220,7 @@ export const Paste = Extension.create<IPasteOptions>({
} }
// 处理 markdown // 处理 markdown
if (markdownText || isMarkdown(text) || html.length === 0 || pasteCodeLanguage === 'markdown') { if (markdownText || isMarkdown(text)) {
event.preventDefault(); event.preventDefault();
const schema = view.props.state.schema; const schema = view.props.state.schema;
const doc = markdownToProsemirror({ const doc = markdownToProsemirror({
@ -239,10 +239,6 @@ export const Paste = Extension.create<IPasteOptions>({
return true; return true;
} }
if (text.length !== 0) {
return insertText(view, text);
}
return false; return false;
}, },
handleDrop: (view, event: any) => { handleDrop: (view, event: any) => {