Editor.js: Does not focus block when using insert()

Created on 24 Sep 2019  Â·  3Comments  Â·  Source: codex-team/editor.js

Hi there, thanks so much for your work on this!

I'm using insert() to add a new block when a user clicks a button:

insert(blockType) {
  // need to be explicit with index, otherwise editor.js adds block at the beginning...
  const index = editor.blocks.getBlocksCount() + 1
  editor.blocks.insert(blockType, {}, {}, index, true)
}
<ul>
  <li @click="insert('header')">Title</li>
  <li @click="insert('paragraph')">Text</li>
</ul>

Even though I set the last param (needToFocus) to true, it doesn't focus the newly inserted block.

Of course, you can use the Caret API to focus the last inserted block like so:

editor.caret.setToLastBlock('start', 0)

... but then what is the needToFocus param for in the insert() method? :)

bug

All 3 comments

BUMP -> What's the status of this? I'm running into this issue as well.

We've found some misunderstanding in usage of needToFocus param. Actually, it does not set a caret for now but changes the focused (highlighted) state of the block.

We will change its behaviour in the next versions.

I tried to use ‘api.caret.setToBlock('end', blockIndex)’ to make it work fine. But it always returns false.
By the way,How can I move the cursor to this new block

Was this page helpful?
3 / 5 - 1 ratings

Related issues

oknoorap picture oknoorap  Â·  4Comments

vsvanshi picture vsvanshi  Â·  4Comments

hata6502 picture hata6502  Â·  3Comments

guillaumepn picture guillaumepn  Â·  4Comments

Someskumarasamy picture Someskumarasamy  Â·  4Comments