codex-team / codex-team/editor.js
[Bug] Block.insert() does not focus on inserted Block if 'needToFocus' is 'true'
- Dominant language
- TypeScript
- Stars
- 31.9k
- Forks
- 2.2k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
Steps to reproduce:
1. In your code call: `this.api.blocks.insert(undefined, undefined, undefined, undefined, true);`
2. Result: A new block will be inserted. The carret stays on the old block. The new block doesn't get focus.
Expected behavior:
After creating a new block by calling the api it should get focus if `needToFocus` is set `true`
Screenshots:
none
Device, Browser, OS:
latest Chrome, Win 10
Editor.js version:
2.18.0
Plugins used with this versions:
My custom plugin (under development)
The Solution I found:
```
this.api.blocks.insert('mytool', undefined, undefined, undefined, true);
window.setTimeout(event => {
this.api.blocks.getBlockByIndex(this.api.blocks.getCurrentBlockIndex())
.holder.querySelector('.' + this.CSS.header)
.focus();
}, 200);
```
is there a better way to achieve this?
thank you!
---------------------------------
a bit later:
I just found that the following solution would probably be better than my first one, but still, it seems to be a bug, that i even have to do this with `needsToFocus = true`
```
this.api.blocks.insert('tgsinfolist', undefined, undefined, undefined, true);
this.api.caret.setToBlock(this.api.blocks.getCurrentBlockIndex());
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.