diff options
author | bobzel <zzzman@gmail.com> | 2022-11-02 13:06:48 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2022-11-02 13:06:48 -0400 |
commit | 770f546a38d7ec827bff55fd0dd64b873a112180 (patch) | |
tree | a3be0c8dc6e888f674fc3cf94cada37d279c4828 | |
parent | b171b939743de6126f3fb5ca1e2d34bba7cbe428 (diff) |
fro
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index ee97e5e62..e9f59f17d 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -1399,11 +1399,13 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FieldViewProps this._editorView.dispatch(this._editorView.state.tr.addStoredMark(schema.marks.user_mark.create({ userid: Doc.CurrentUserEmail, modified: Math.floor(Date.now() / 1000) }))); } } - if (FormattedTextBox.DontSelectInitialText) setTimeout(() => selectOnLoad && this._editorView!.focus(), 0); - else selectOnLoad && this._editorView!.focus(); - FormattedTextBox.DontSelectInitialText = false; + selectOnLoad && this._editorView!.focus(); // add user mark for any first character that was typed since the user mark that gets set in KeyPress won't have been called yet. if (this._editorView) { + const tr = this._editorView.state.tr; + const { from, to } = tr.selection; + // for some reason, the selection is sometimes lost in the sidebar view when prosemirror syncs the seledtion with the dom, so reset the selectoin after the document has ben fully instantiated. + if (FormattedTextBox.DontSelectInitialText) setTimeout(() => this._editorView?.dispatch(tr.setSelection(new TextSelection(tr.doc.resolve(from), tr.doc.resolve(to)))), 250); this._editorView.state.storedMarks = [ ...(this._editorView.state.storedMarks ?? []), ...(!this._editorView.state.storedMarks?.some(mark => mark.type === schema.marks.user_mark) ? [schema.marks.user_mark.create({ userid: Doc.CurrentUserEmail, modified: Math.floor(Date.now() / 1000) })] : []), @@ -1415,6 +1417,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FieldViewProps ...(Doc.UserDoc().fontWeight === 'bold' ? [schema.mark(schema.marks.strong)] : []), ]; } + FormattedTextBox.DontSelectInitialText = false; } componentWillUnmount() { |