Closed ocavue closed 2 months ago
same question
I also encountered a similar situation, but in my case, I wanted the cursor to automatically focus on the beginning of the document. However, every time, I noticed the cursor appearing at the end, and then I had to wait for some time after creating the editorView, using setTimeout, before executing the operation to move the cursor to the starting position. Was this issue resolved later?
A fix is now available in y-prosemirror@1.2.6
Checklist
Describe the bug
I want to initialize the editor with a particular selection position (e.g. at the start of the document), but y-prosemirror always changes the initial selection to the end of the document.
ProseMirror allows me to set the initial selection by providing an initial editor state with a selection. The code is shown below:
Even if the initial selection is not implicitly passed, the default selection is at the start of the document.
When I use
ySyncPlugin
,_forceRerender
will replace the content of the whole document, which make the selection at the end of the document.To Reproduce
I prepare a simple example based on the
demo/
example in this repo. You can find the code here.Go to http://127.0.0.1:8081/demo/prosemirror.html. The editor should be focused and the caret is at the end of the document.
If
ENABLE_YJS
indemo/prosemirror.js
is set asfalse
, then they-prosemirror
in the heading will be selected after a reload.Notice that in this example, to set the initial selection, I have to pass the initial document with two different ways in the same time:
doc
toEditorState
.yDoc
toySyncPlugin
.Expected behavior
I can set the initial selection when using y-prosemirror.
Screenshots
https://user-images.githubusercontent.com/24715727/191005843-46a93d9c-9e5e-4ffc-85cc-4f46a60a0294.mp4
Environment Information
Additional context
I created a PR https://github.com/yjs/y-prosemirror/pull/127 to resolve this issue.