bustle/mobiledoc-kit

autofocus only works if Editor is created with a mobiledoc

gpoitch opened this issue · 5 comments

This currently will not autofocus, because there is no document, therefore nowhere to place the cursor:

const editor = new Mobiledoc.Editor({
  placeholder: 'Write here...',
  autofocus: true
})

This works:

const editor = new Mobiledoc.Editor({
  placeholder: 'Write here...',
  autofocus: true,
  mobiledoc: {
    version: '0.3.0',
    markups: [],
    atoms: [],
    cards: [],
    sections: [[1, "p", [[0, [], 0, ""]]]]
  }
})

Auto-creating a blank mobiledoc if not provided may have some unwanted side effects.
Perhaps offering a public constant to a blank doc could be a compromise:

const editor = new Mobiledoc.Editor({
  placeholder: 'Write here...',
  autofocus: true,
  mobiledoc: Mobiledoc.BlankMobiledoc
})

Agreed, added this to the draft features 1.0 doc, will make a milestone or something today.

Also ran into this issue.

Minor nit: autofocus only works if Editor is created with a mobiledoc with sections. That is to say, the EMPTY_MOBILEDOC in ember-mobiledoc-editor will not suffice.

FWIW, seems like this fix doesn't work in Safari. It's unclear if it's due to something specific in our implementation or a more general problem.

Seems that editor.selectRange(editor.post.headPosition()) does not work in Safari