-
-
Notifications
You must be signed in to change notification settings - Fork 149
Description
Checklist
- Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
- Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/
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:
const prosemirrorView = new EditorView(editor, {
state: EditorState.create({
doc,
selection, // <-- here is my initial selection
schema,
plugins: [...]
})
})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.
$ git clone https://github.com/ocavue/y-prosemirror -b ocavue/init_selection
$ cd y-prosemirror
$ npm install
$ npm run start
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 in demo/prosemirror.js is set as false, then the y-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:
- pass the
doctoEditorState. - pass the
yDoctoySyncPlugin.
Expected behavior
I can set the initial selection when using y-prosemirror.
Screenshots
yjs-selection.mp4
Environment Information
- Browser: Chrome version 105
- Yjs version and the versions of the y-* modules you are using
- y-prosemirror@1.1.3
- yjs@13.5.38
Additional context
I created a PR #127 to resolve this issue.