codex-team / codex-team/editor.js

Does not focus block when using insert()

Open
#899 5 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
31.9k
Forks
2.2k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

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:

```js
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)
}
```

```vue


  • Title

  • Text


```

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:

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

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.