fix: initialize autofocus selection in createView (#2212)

* initialize autofocus selection in `createView`

* fix missing variable and null error

* remove unused imports
This commit is contained in:
BrianHung
2021-12-03 01:35:17 -08:00
committed by GitHub
parent 4e1a50250b
commit de39853026
3 changed files with 31 additions and 46 deletions

View File

@@ -12,6 +12,7 @@ import createDocument from './helpers/createDocument'
import getHTMLFromFragment from './helpers/getHTMLFromFragment'
import getText from './helpers/getText'
import isNodeEmpty from './helpers/isNodeEmpty'
import resolveFocusPosition from './helpers/resolveFocusPosition'
import getTextSeralizersFromSchema from './helpers/getTextSeralizersFromSchema'
import createStyleTag from './utilities/createStyleTag'
import isFunction from './utilities/isFunction'
@@ -260,11 +261,14 @@ export class Editor extends EventEmitter<EditorEvents> {
* Creates a ProseMirror view.
*/
private createView(): void {
const doc = createDocument(this.options.content, this.schema, this.options.parseOptions)
const selection = resolveFocusPosition(doc, this.options.autofocus)
this.view = new EditorView(this.options.element, {
...this.options.editorProps,
dispatchTransaction: this.dispatchTransaction.bind(this),
state: EditorState.create({
doc: createDocument(this.options.content, this.schema, this.options.parseOptions),
doc,
selection,
}),
})