Fix BlockManager.insert method (#1172)

* Fix BlockManager.insert method

* upd

* Explicitly check for undefined
This commit is contained in:
George Berezhnoy 2020-06-02 14:14:01 +03:00 committed by GitHub
parent ffe5bbc8fc
commit ff6bd2dedf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

2
dist/editor.js vendored

File diff suppressed because one or more lines are too long

View file

@ -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++;
}