codex-team / codex-team/editor.js
getCurrentBlockIndex returns different numbers depending on how/if the block has been moved
- Dominant language
- TypeScript
- Stars
- 31.9k
- Forks
- 2.2k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
according to the documentation, `getCurrentBlockIndex` should return 0 for the first block:
```
isFirstBlock() {
return this.api.blocks.getCurrentBlockIndex() === 0;
}
// taken from https://editorjs.io/blocks#getcurrentblockindex
```
however, `getCurrentBlockIndex` returns `realindex -1` on initialization and when the block has been moved **down**
and `realindex + 1` when the block has been moved **up**:
this makes it impossible to programmatically insert items after the current bock
# Demo
to demonstrate, @natterstefan (thanks a lot :rocket: ) set up a demo that logs the currentBlockIndex in a custom plugin (on render and on moved)
https://codepen.io/natterstefan/pen/eYNQObo?editors=1111
## initialization
the block using the custom plugin is the third block
on render, `api.blocks.getCurrentBlockIndex()` returns 1 (instead of 2)
## moving up
moving the block **up** to the second position, makes `moved()` log 2 (instead of 1)
moving the block to the first position: logs 1 (instead of 0)
## moving down
moving the block **down** to the second position: logs 0 (instead of 1)
moving the block **down** to the third position: logs 1 (instead of 2)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.