Saul-Mirone / prosemirror-adapter

Universal adapter to create prosemirror nodeview from modern UI frameworks.
MIT License
97 stars 7 forks source link

[Svelte] Is there a way to restore the cursor location when a node's value is modified via setAttrs? #37

Open dev-guy opened 1 year ago

dev-guy commented 1 year ago

When combining Milkdown and prosemirror-adapter/svelte, setAttrs({ value: 5 }) causes the Svelte component (declared via $view) to be removed and a new component takes its place. In my case, the Svelte component consists of a textarea. setAtrrs() moves the cursor out of the textarea to the top of the Milkdown editor. I guess I could capture the cursor location in update() but I'm not sure what I could do to find it later when the new Svelte component is created. I think I'm supposed to use a Svelte store for this. Is that correct? I realize that a better solution is to use a Prosemirror Editor instead of textarea and use transactions (which has better support for undo/redo and collaboration), but that's what the Milkdown Playground does eg with the diagram plugin.