mirror of
https://github.com/codex-team/editor.js
synced 2026-03-17 08:05:47 +01:00
Delete Tune improvements
This commit is contained in:
parent
d0126e04e3
commit
088a537397
4 changed files with 69 additions and 19 deletions
|
|
@ -2376,7 +2376,22 @@ var BlocksAPI = function (_Module) {
|
|||
value: function _delete(blockIndex) {
|
||||
this.Editor.BlockManager.removeBlock(blockIndex);
|
||||
this.Editor.Toolbar.close();
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
/**
|
||||
* in case of last block deletion
|
||||
* Insert new initial empty block
|
||||
*/
|
||||
if (this.Editor.BlockManager.blocks.length === 0) {
|
||||
this.Editor.BlockManager.insert();
|
||||
}
|
||||
/**
|
||||
* In case of deletion first block we need to set caret to the next block by index
|
||||
* but next jumped up after removing, so set caret to the current block means to set it to next
|
||||
*/
|
||||
if (this.Editor.BlockManager.currentBlockIndex === 0) {
|
||||
this.Editor.Caret.setToBlock(this.Editor.BlockManager.currentBlock);
|
||||
} else {
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'methods',
|
||||
|
|
@ -2900,16 +2915,14 @@ var BlockManager = function (_Module) {
|
|||
* Set's caret to the next Block
|
||||
* Before moving caret, we should check if caret position is at the end of Plugins node
|
||||
* Using {@link Dom#getDeepestNode} to get a last node and match with current selection
|
||||
*
|
||||
* @param {Boolean} force - force navigation
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'navigateNext',
|
||||
value: function navigateNext() {
|
||||
var caretAtEnd = this.Editor.Caret.isAtEnd;
|
||||
|
||||
if (!caretAtEnd) {
|
||||
return;
|
||||
}
|
||||
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
||||
|
||||
var nextBlock = this.nextBlock;
|
||||
|
||||
|
|
@ -2917,6 +2930,17 @@ var BlockManager = function (_Module) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (force) {
|
||||
this.Editor.Caret.setToBlock(nextBlock, 0, true);
|
||||
return;
|
||||
}
|
||||
|
||||
var caretAtEnd = this.Editor.Caret.isAtEnd;
|
||||
|
||||
if (!caretAtEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.Editor.Caret.setToBlock(nextBlock);
|
||||
}
|
||||
|
||||
|
|
@ -2956,7 +2980,7 @@ var BlockManager = function (_Module) {
|
|||
/**
|
||||
* Insert new block into _blocks
|
||||
*
|
||||
* @param {String} toolName — plugin name
|
||||
* @param {String} toolName — plugin name, by default method inserts initial block type
|
||||
* @param {Object} data — plugin data
|
||||
* @param {Object} settings - default settings
|
||||
*
|
||||
|
|
@ -2965,7 +2989,8 @@ var BlockManager = function (_Module) {
|
|||
|
||||
}, {
|
||||
key: 'insert',
|
||||
value: function insert(toolName) {
|
||||
value: function insert() {
|
||||
var toolName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.config.initialBlock;
|
||||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
|
||||
|
|
@ -3335,7 +3360,7 @@ var Blocks = function () {
|
|||
}, {
|
||||
key: 'remove',
|
||||
value: function remove(index) {
|
||||
if (!index) {
|
||||
if (isNaN(index)) {
|
||||
index = this.length - 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -49,7 +49,24 @@ export default class BlocksAPI extends Module implements IBlocksAPI {
|
|||
public delete(blockIndex?: number): void {
|
||||
this.Editor.BlockManager.removeBlock(blockIndex);
|
||||
this.Editor.Toolbar.close();
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
|
||||
/**
|
||||
* in case of last block deletion
|
||||
* Insert new initial empty block
|
||||
*/
|
||||
if (this.Editor.BlockManager.blocks.length === 0) {
|
||||
this.Editor.BlockManager.insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* In case of deletion first block we need to set caret to the next block by index
|
||||
* but next jumped up after removing, so set caret to the current block means to set it to next
|
||||
*/
|
||||
if (this.Editor.BlockManager.currentBlockIndex === 0) {
|
||||
this.Editor.Caret.setToBlock(this.Editor.BlockManager.currentBlock);
|
||||
} else {
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,21 +109,29 @@ export default class BlockManager extends Module {
|
|||
* Set's caret to the next Block
|
||||
* Before moving caret, we should check if caret position is at the end of Plugins node
|
||||
* Using {@link Dom#getDeepestNode} to get a last node and match with current selection
|
||||
*
|
||||
* @param {Boolean} force - force navigation
|
||||
*/
|
||||
navigateNext() {
|
||||
let caretAtEnd = this.Editor.Caret.isAtEnd;
|
||||
|
||||
if (!caretAtEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
navigateNext(force = false) {
|
||||
let nextBlock = this.nextBlock;
|
||||
|
||||
if (!nextBlock) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.Editor.Caret.setToBlock( nextBlock );
|
||||
if (force) {
|
||||
this.Editor.Caret.setToBlock(nextBlock, 0, true);
|
||||
return;
|
||||
}
|
||||
|
||||
let caretAtEnd = this.Editor.Caret.isAtEnd;
|
||||
|
||||
if (!caretAtEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.Editor.Caret.setToBlock(nextBlock);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -157,13 +165,13 @@ export default class BlockManager extends Module {
|
|||
/**
|
||||
* Insert new block into _blocks
|
||||
*
|
||||
* @param {String} toolName — plugin name
|
||||
* @param {String} toolName — plugin name, by default method inserts initial block type
|
||||
* @param {Object} data — plugin data
|
||||
* @param {Object} settings - default settings
|
||||
*
|
||||
* @return {Block}
|
||||
*/
|
||||
insert(toolName, data = {}, settings = {}) {
|
||||
insert(toolName = this.config.initialBlock, data = {}, settings = {}) {
|
||||
let block = this.composeBlock(toolName, data, settings);
|
||||
|
||||
this._blocks[++this.currentBlockIndex] = block;
|
||||
|
|
@ -465,7 +473,7 @@ class Blocks {
|
|||
* @param {Number|null} index
|
||||
*/
|
||||
remove(index) {
|
||||
if (!index) {
|
||||
if (isNaN(index)) {
|
||||
index = this.length - 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue