Code to do paste equivalent of Ctrl + v #1508
-
I'm using Windows, and when I use
In all of the above cases, a keyboard paste creates the proper node -- So, now I have added a context menu to my editor so that I can use it to paste (this is Svelte code): <EditorContextMenu handlePaste={handlePaste}>
<div use:editor />
</EditorContextMenu> However, in order to determine what kind of node to create (text, image, audio, video), I would have to parse the above markdown (or remark directives) and extract the E.g., for image, the code I'm trying is: let handlePaste = (content: string) => {
theEditor.editor.action((ctx: Ctx) => {
const schema = ctx.get(schemaCtx);
const editorView = ctx.get(editorViewCtx);
// the following will not work ...
// it creates of course, ![some jpg](![some jpg](/api/images/some_image.jpg))
// const node = schema.nodes.image.create({src: content});
// what I am looking for is something like...:
const node = schema.nodes.create_from_markdown(content); // doesn't exist
editorView.dispatch(editorView.state.tr.insert(3, node));
});
theEditor.focus();
} How does Milkdown do, essentially, Also, how to get current cursor position (instead of hard coded Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I apologize for missing the obvious. The solution is simply: let handlePaste = (content: string) => {
theEditor.editor.action(insert(content));
theEditor.focus();
} |
Beta Was this translation helpful? Give feedback.
I apologize for missing the obvious. The solution is simply: