Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show warning if Block to delete is not found #1111

Merged
merged 4 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/components/modules/api/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ export default class BlocksAPI extends Module {
* @param {number} blockIndex - index of Block to delete
*/
public delete(blockIndex?: number): void {
this.Editor.BlockManager.removeBlock(blockIndex);
try {
this.Editor.BlockManager.removeBlock(blockIndex);
} catch (e) {
_.logLabeled(e, 'warn');

return;
}

/**
* in case of last block deletion
Expand Down
11 changes: 8 additions & 3 deletions src/components/modules/blockManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,16 @@ export default class BlockManager extends Module {
* Remove block with passed index or remove last
*
* @param {number|null} index - index of Block to remove
* @throws {Error} if Block to remove is not found
*/
public removeBlock(index?: number): void {
if (index === undefined) {
index = this.currentBlockIndex;
public removeBlock(index = this.currentBlockIndex): void {
/**
* If index is not passed and there is no block selected, show a warning
*/
if (index === -1) {
throw new Error('Can\'t find a Block to remove');
}

this._blocks.remove(index);

if (this.currentBlockIndex >= index) {
Expand Down