yjs / y-prosemirror

ProseMirror editor binding for Yjs
https://demos.yjs.dev/prosemirror/prosemirror.html
MIT License
345 stars 120 forks source link

default-selection-autofocus #62

Open BrianHung opened 3 years ago

BrianHung commented 3 years ago

This PR removes hardcoded 0 value which assumes that a selection at the beginning of a document Selection.atStart has a position of 0. Depending on the document type, a valid selection at the start of the document may begin at a value larger than that (relevant comment: https://github.com/ueberdosis/tiptap/pull/1595#issuecomment-896444524).

Mainly fixes issue of autofocusing editor on mount and on yjs content load: selection is at beginning of document before yjs content load, and is at end of document after yjs load. Expected behavior is that selection stays at beginning of document.

absolutePositionToRelativePosition might still contain additional bugs because 1. there are other pos == 0 statements in the function logic 2. unknown whether (initial) selections at end of the document Selection.atEnd have problems.