mirror of https://github.com/fantasticit/think.git
fix paste file
This commit is contained in:
parent
b0e32f0c94
commit
87bccec882
|
@ -14,14 +14,9 @@ import {
|
|||
isMarkdown,
|
||||
isValidURL,
|
||||
normalizeMarkdown,
|
||||
safePos,
|
||||
} from 'tiptap/prose-utils';
|
||||
|
||||
const safePos = (state: EditorState, pos) => {
|
||||
if (pos < 0) return 0;
|
||||
|
||||
return Math.min(state.doc.content.size, pos);
|
||||
};
|
||||
|
||||
const htmlToProsemirror = (editor: CoreEditor, html, isPasteMarkdown = false) => {
|
||||
const firstNode = editor.view.state.doc.content.firstChild;
|
||||
const shouldInsertTitleText = !!(firstNode?.textContent?.length <= 0 ?? true);
|
||||
|
@ -188,7 +183,7 @@ export const Paste = Extension.create<IPasteOptions>({
|
|||
const vscodeMeta = vscode ? JSON.parse(vscode) : undefined;
|
||||
const pasteCodeLanguage = vscodeMeta?.mode;
|
||||
|
||||
if (html.length > 0 || text.length === 0) {
|
||||
if (html.length > 0) {
|
||||
return htmlToProsemirror(editor, html);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* Copyright 2021, Milkdown by Mirone. */
|
||||
import { EditorState } from 'prosemirror-state';
|
||||
import type { EditorView } from 'prosemirror-view';
|
||||
|
||||
type Point = [top: number, left: number];
|
||||
|
@ -59,3 +60,9 @@ export const calculateTextPosition = (
|
|||
target.style.top = top + 'px';
|
||||
target.style.left = left + 'px';
|
||||
};
|
||||
|
||||
export const safePos = (state: EditorState, pos) => {
|
||||
if (pos < 0) return 0;
|
||||
|
||||
return Math.min(state.doc.content.size, pos);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue