* Check if user clicks on the Editor's bottom zone: * - set caret to the last block * - or add new empty block * * @param event - click event
(event: MouseEvent)
| 798 | * @param event - click event |
| 799 | */ |
| 800 | private processBottomZoneClick(event: MouseEvent): void { |
| 801 | const lastBlock = this.Editor.BlockManager.getBlockByIndex(-1); |
| 802 | |
| 803 | const lastBlockBottomCoord = $.offset(lastBlock.holder).bottom; |
| 804 | const clickedCoord = event.pageY; |
| 805 | const { BlockSelection } = this.Editor; |
| 806 | const isClickedBottom = event.target instanceof Element && |
| 807 | event.target.isEqualNode(this.nodes.redactor) && |
| 808 | /** |
| 809 | * If there is cross block selection started, target will be equal to redactor so we need additional check |
| 810 | */ |
| 811 | !BlockSelection.anyBlockSelected && |
| 812 | |
| 813 | /** |
| 814 | * Prevent caret jumping (to last block) when clicking between blocks |
| 815 | */ |
| 816 | lastBlockBottomCoord < clickedCoord; |
| 817 | |
| 818 | if (isClickedBottom) { |
| 819 | event.stopImmediatePropagation(); |
| 820 | event.stopPropagation(); |
| 821 | |
| 822 | const { BlockManager, Caret, Toolbar } = this.Editor; |
| 823 | |
| 824 | /** |
| 825 | * Insert a default-block at the bottom if: |
| 826 | * - last-block is not a default-block (Text) |
| 827 | * to prevent unnecessary tree-walking on Tools with many nodes (for ex. Table) |
| 828 | * - Or, default-block is not empty |
| 829 | */ |
| 830 | if (!BlockManager.lastBlock.tool.isDefault || !BlockManager.lastBlock.isEmpty) { |
| 831 | BlockManager.insertAtEnd(); |
| 832 | } |
| 833 | |
| 834 | /** |
| 835 | * Set the caret and toolbar to empty Block |
| 836 | */ |
| 837 | Caret.setToTheLastBlock(); |
| 838 | Toolbar.moveAndOpen(BlockManager.lastBlock); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Handle selection changes on mobile devices |
no test coverage detected