mirror of
https://github.com/codex-team/editor.js
synced 2026-03-17 08:05:47 +01:00
save
This commit is contained in:
parent
e2041c9375
commit
c92f3f9af1
5 changed files with 44 additions and 80 deletions
|
|
@ -1559,15 +1559,21 @@ var BlockManager = function (_Module) {
|
|||
|
||||
var blockToMergeIndex = this._blocks.indexOf(blockToMerge);
|
||||
|
||||
if (blockToMerge.isEmpty) {
|
||||
return new Promise(function (resolve) {
|
||||
|
||||
this.removeBlock(blockToMergeIndex);
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (blockToMerge.isEmpty) {
|
||||
|
||||
return blockToMerge.data.then(function (blockToMergeInfo) {
|
||||
resolve();
|
||||
} else {
|
||||
|
||||
blockToMerge.data.then(function (blockToMergeInfo) {
|
||||
|
||||
targetBlock.mergeWith(blockToMergeInfo.data);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
}).then(function () {
|
||||
|
||||
targetBlock.mergeWith(blockToMergeInfo.data);
|
||||
_this4.removeBlock(blockToMergeIndex);
|
||||
});
|
||||
}
|
||||
|
|
@ -1602,14 +1608,9 @@ var BlockManager = function (_Module) {
|
|||
* @todo make object in accordance with Tool
|
||||
*/
|
||||
var data = {
|
||||
text: wrapper.textContent.trim() === '' ? '' : wrapper.innerHTML
|
||||
text: $.isEmpty(wrapper) ? '' : wrapper.innerHTML
|
||||
};
|
||||
|
||||
if (this.currentBlock.isEmpty) {
|
||||
|
||||
this.currentBlock.pluginsContent.innerHTML = '';
|
||||
}
|
||||
|
||||
this.insert(this.config.initialBlock, data);
|
||||
}
|
||||
|
||||
|
|
@ -1637,35 +1638,14 @@ var BlockManager = function (_Module) {
|
|||
*/
|
||||
|
||||
}, {
|
||||
key: 'getBlockIndex',
|
||||
key: 'getBlockByIndex',
|
||||
|
||||
|
||||
/**
|
||||
* Returns block's index
|
||||
* @param {Block} block
|
||||
* @return {Number}
|
||||
*/
|
||||
value: function getBlockIndex(block) {
|
||||
|
||||
for (var i = 0; i < this._blocks.length; i++) {
|
||||
|
||||
if (this._blocks[i] === block) {
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Block by passed index
|
||||
* @param {Number} index
|
||||
* @return {Block}
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'getBlockByIndex',
|
||||
value: function getBlockByIndex(index) {
|
||||
|
||||
return this._blocks[index];
|
||||
|
|
@ -2778,7 +2758,7 @@ var Keyboard = function (_Module) {
|
|||
case _.keyCodes.BACKSPACE:
|
||||
|
||||
_.log('Backspace key pressed');
|
||||
this.backSpacePressed(event);
|
||||
this.backspacePressed(event);
|
||||
break;
|
||||
|
||||
case _.keyCodes.ENTER:
|
||||
|
|
@ -2851,12 +2831,12 @@ var Keyboard = function (_Module) {
|
|||
*/
|
||||
|
||||
}, {
|
||||
key: 'backSpacePressed',
|
||||
value: function backSpacePressed(event) {
|
||||
key: 'backspacePressed',
|
||||
value: function backspacePressed(event) {
|
||||
var _this2 = this;
|
||||
|
||||
var isFirstBlock = this.Editor.BlockManager.currentBlockIndex === 0,
|
||||
canMergeBlocks = !this.Editor.BlockManager.currentBlock.hasMedia && this.Editor.Caret.isAtStart && !isFirstBlock;
|
||||
canMergeBlocks = (this.Editor.BlockManager.currentBlock.isEmpty || this.Editor.Caret.isAtStart) && !isFirstBlock;
|
||||
|
||||
if (!canMergeBlocks) {
|
||||
|
||||
|
|
@ -2869,7 +2849,7 @@ var Keyboard = function (_Module) {
|
|||
var targetBlock = this.Editor.BlockManager.getBlockByIndex(this.Editor.BlockManager.currentBlockIndex - 1),
|
||||
blockToMerge = this.Editor.BlockManager.currentBlock;
|
||||
|
||||
if (blockToMerge.name !== targetBlock.name || !this.Editor.BlockManager.currentBlock.mergeable) {
|
||||
if (blockToMerge.name !== targetBlock.name || !targetBlock.mergeable) {
|
||||
|
||||
this.Editor.BlockManager.navigatePrevious();
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -122,7 +122,7 @@ export default class Block {
|
|||
mergeWith(data) {
|
||||
|
||||
return Promise.resolve()
|
||||
.then( () => {
|
||||
.then(() => {
|
||||
|
||||
this.tool.merge(data);
|
||||
|
||||
|
|
|
|||
|
|
@ -206,21 +206,32 @@ export default class BlockManager extends Module {
|
|||
|
||||
let blockToMergeIndex = this._blocks.indexOf(blockToMerge);
|
||||
|
||||
if (blockToMerge.isEmpty) {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
this.removeBlock(blockToMergeIndex);
|
||||
return Promise.resolve();
|
||||
if (blockToMerge.isEmpty) {
|
||||
|
||||
}
|
||||
resolve();
|
||||
|
||||
return blockToMerge.data
|
||||
.then((blockToMergeInfo) => {
|
||||
} else {
|
||||
|
||||
blockToMerge.data
|
||||
.then((blockToMergeInfo) => {
|
||||
|
||||
targetBlock.mergeWith(blockToMergeInfo.data);
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
.then( () => {
|
||||
|
||||
targetBlock.mergeWith(blockToMergeInfo.data);
|
||||
this.removeBlock(blockToMergeIndex);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -248,15 +259,9 @@ export default class BlockManager extends Module {
|
|||
* @todo make object in accordance with Tool
|
||||
*/
|
||||
let data = {
|
||||
text: wrapper.textContent.trim() === '' ? '' : wrapper.innerHTML,
|
||||
text: $.isEmpty(wrapper) ? '' : wrapper.innerHTML,
|
||||
};
|
||||
|
||||
if (this.currentBlock.isEmpty) {
|
||||
|
||||
this.currentBlock.pluginsContent.innerHTML = '';
|
||||
|
||||
}
|
||||
|
||||
this.insert(this.config.initialBlock, data);
|
||||
|
||||
}
|
||||
|
|
@ -285,27 +290,6 @@ export default class BlockManager extends Module {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns block's index
|
||||
* @param {Block} block
|
||||
* @return {Number}
|
||||
*/
|
||||
getBlockIndex(block) {
|
||||
|
||||
for(let i = 0; i < this._blocks.length; i++) {
|
||||
|
||||
if (this._blocks[i] === block) {
|
||||
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Block by passed index
|
||||
* @param {Number} index
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export default class Keyboard extends Module {
|
|||
case _.keyCodes.BACKSPACE:
|
||||
|
||||
_.log('Backspace key pressed');
|
||||
this.backSpacePressed(event);
|
||||
this.backspacePressed(event);
|
||||
break;
|
||||
|
||||
case _.keyCodes.ENTER:
|
||||
|
|
@ -107,10 +107,10 @@ export default class Keyboard extends Module {
|
|||
* Handle backspace keypress on block
|
||||
* @param event
|
||||
*/
|
||||
backSpacePressed(event) {
|
||||
backspacePressed(event) {
|
||||
|
||||
let isFirstBlock = this.Editor.BlockManager.currentBlockIndex === 0,
|
||||
canMergeBlocks = !this.Editor.BlockManager.currentBlock.hasMedia && this.Editor.Caret.isAtStart && !isFirstBlock;
|
||||
canMergeBlocks = (this.Editor.BlockManager.currentBlock.isEmpty || this.Editor.Caret.isAtStart) && !isFirstBlock;
|
||||
|
||||
if (!canMergeBlocks) {
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ export default class Keyboard extends Module {
|
|||
blockToMerge = this.Editor.BlockManager.currentBlock;
|
||||
|
||||
|
||||
if (blockToMerge.name !== targetBlock.name || !this.Editor.BlockManager.currentBlock.mergeable) {
|
||||
if (blockToMerge.name !== targetBlock.name || !targetBlock.mergeable) {
|
||||
|
||||
this.Editor.BlockManager.navigatePrevious();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue