Skip to content

Commit

Permalink
Fix BlockManager.insert method (codex-team#1172)
Browse files Browse the repository at this point in the history
* Fix BlockManager.insert method

* upd

* Explicitly check for undefined
  • Loading branch information
gohabereg authored Jun 2, 2020
1 parent ffe5bbc commit ff6bd2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/components/modules/blockManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}: {
Expand All @@ -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++;
}

Expand Down

0 comments on commit ff6bd2d

Please sign in to comment.