Create a new block when clicked at the bottom (#1605)

* Create a new block when clicked at the bottom

* Fix for 2.20.0

Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com>
This commit is contained in:
Tomoyuki Hata 2021-04-09 03:38:08 +09:00 committed by GitHub
parent 9cdda110da
commit aa5a3d05f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -2,6 +2,7 @@
### 2.20.1
- `Fix` - Create a new block when clicked at the bottom [#1588](https://github.com/codex-team/editor.js/issues/1588).
- `Fix` — Fix sanitisation problem with Inline Tools [#1631](https://github.com/codex-team/editor.js/issues/1631)
- `Refactoring` - The Sanitizer module is util now.
- `Refactoring` - Tooltip module is util now.

View file

@ -691,10 +691,28 @@ export default class UI extends Module<UINodes> {
return;
}
if (!this.Editor.BlockManager.currentBlock) {
const isClickedBottom = event.target instanceof Element && event.target.isEqualNode(this.nodes.redactor);
if (isClickedBottom) {
stopPropagation();
this.Editor.BlockManager.insert();
const { BlockManager, Caret, Toolbar } = this.Editor;
/**
* Insert a default-block at the bottom if:
* - last-block is not a default-block (Text)
* to prevent unnecessary tree-walking on Tools with many nodes (for ex. Table)
* - Or, default-block is not empty
*/
if (!BlockManager.lastBlock.tool.isDefault || !BlockManager.lastBlock.isEmpty) {
BlockManager.insertAtEnd();
}
/**
* Set the caret and toolbar to empty Block
*/
Caret.setToTheLastBlock();
Toolbar.move();
}
/**