mirror of
https://github.com/codex-team/editor.js
synced 2026-03-15 15:15:47 +01:00
Delete tune fixes
This commit is contained in:
parent
c6656770e5
commit
9c41fc402b
4 changed files with 82 additions and 14 deletions
|
|
@ -2363,7 +2363,15 @@ var BlocksAPI = function (_Module) {
|
|||
value: function _delete(blockIndex) {
|
||||
this.Editor.BlockManager.removeBlock(blockIndex);
|
||||
this.Editor.Toolbar.close();
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
var navigatetoCurrent = false;
|
||||
if (this.Editor.BlockManager.currentBlockIndex === 0) {
|
||||
navigatetoCurrent = true;
|
||||
}
|
||||
if (navigatetoCurrent) {
|
||||
this.Editor.BlockManager.setToCurrentBlock();
|
||||
} else {
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'methods',
|
||||
|
|
@ -2887,16 +2895,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;
|
||||
|
||||
|
|
@ -2904,9 +2910,39 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Boolean} atTheEnd - Set the caret at the end or at the start
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'setToCurrentBlock',
|
||||
value: function setToCurrentBlock() {
|
||||
var atTheEnd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
||||
|
||||
var currentBlock = this.currentBlock;
|
||||
|
||||
if (!currentBlock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.Editor.Caret.setToBlock(currentBlock, 0, atTheEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set's caret to the previous Block
|
||||
* Before moving caret, we should check if caret position is start of the Plugins node
|
||||
|
|
@ -3312,7 +3348,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
|
|
@ -47,9 +47,20 @@ export default class BlocksAPI extends Module implements IBlocksAPI {
|
|||
* @param blockIndex
|
||||
*/
|
||||
public delete(blockIndex?: number): void {
|
||||
|
||||
this.Editor.BlockManager.removeBlock(blockIndex);
|
||||
this.Editor.Toolbar.close();
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
|
||||
let navigatetoCurrent = false;
|
||||
if (this.Editor.BlockManager.currentBlockIndex === 0) {
|
||||
navigatetoCurrent = true;
|
||||
}
|
||||
|
||||
if (navigatetoCurrent) {
|
||||
this.Editor.BlockManager.setToCurrentBlock();
|
||||
} else {
|
||||
this.Editor.BlockManager.navigatePrevious(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,21 +109,42 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Boolean} atTheEnd - Set the caret at the end or at the start
|
||||
* @return {boolean}
|
||||
*/
|
||||
setToCurrentBlock(atTheEnd = false) {
|
||||
let currentBlock = this.currentBlock;
|
||||
|
||||
if (!currentBlock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.Editor.Caret.setToBlock(currentBlock, 0, atTheEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -455,7 +476,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