mirror of
https://github.com/codex-team/editor.js
synced 2024-06-29 02:40:23 +02:00
Fix BlockManager.insert method (#1172)
* Fix BlockManager.insert method * upd * Explicitly check for undefined
This commit is contained in:
parent
ffe5bbc8fc
commit
ff6bd2dedf
2
dist/editor.js
vendored
2
dist/editor.js
vendored
File diff suppressed because one or more lines are too long
|
@ -239,7 +239,7 @@ export default class BlockManager extends Module {
|
|||
public insert({
|
||||
tool = this.config.initialBlock,
|
||||
data = {},
|
||||
index = this.currentBlockIndex + 1,
|
||||
index,
|
||||
needToFocus = true,
|
||||
replace = false,
|
||||
}: {
|
||||
|
@ -249,16 +249,22 @@ export default class BlockManager extends Module {
|
|||
needToFocus?: boolean;
|
||||
replace?: boolean;
|
||||
} = {}): Block {
|
||||
let newIndex = index;
|
||||
|
||||
if (newIndex === undefined) {
|
||||
newIndex = this.currentBlockIndex + (replace ? 0 : 1);
|
||||
}
|
||||
|
||||
const block = this.composeBlock({
|
||||
tool,
|
||||
data,
|
||||
});
|
||||
|
||||
this._blocks.insert(index, block, replace);
|
||||
this._blocks.insert(newIndex, block, replace);
|
||||
|
||||
if (needToFocus) {
|
||||
this.currentBlockIndex = index;
|
||||
} else if (index <= this.currentBlockIndex) {
|
||||
this.currentBlockIndex = newIndex;
|
||||
} else if (newIndex <= this.currentBlockIndex) {
|
||||
this.currentBlockIndex++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue