merge and split improvements

This commit is contained in:
Murod Khaydarov 2018-05-22 14:53:24 +03:00
commit 7c7f978e61
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
5 changed files with 49 additions and 29 deletions

View file

@ -1536,9 +1536,9 @@ var BlockManager = function (_Module) {
}
/**
*
* @param targetBlock
* @param mergingBlock
* Merge two blocks
* @param {Block} targetBlock - block to merge
* @param {Block} mergingBlock - block that will be merged with target block
*/
}, {
@ -1555,14 +1555,17 @@ var BlockManager = function (_Module) {
mergingBlock = this._blocks[this.currentBlockIndex];
}
var range = document.createRange();
if (mergingBlock.html.textContent.trim() !== '') {
range.selectNodeContents(mergingBlock.pluginsContent);
var range = document.createRange(),
extractedBlock = void 0;
var extracted = range.extractContents();
range.selectNodeContents(mergingBlock.pluginsContent);
extractedBlock = range.extractContents();
targetBlock.pluginsContent.appendChild(extracted);
targetBlock.pluginsContent.normalize();
targetBlock.pluginsContent.appendChild(extractedBlock);
targetBlock.pluginsContent.normalize();
}
this.removeBlock(this.currentBlockIndex);
}
@ -2543,7 +2546,10 @@ var Caret = function (_Module) {
var selection = _Selection2.default.get(),
anchorNode = selection.anchorNode,
lastNode = $.getDeepest;
lastNode = $.getDeepestNode(this.Editor.BlockManager.currentBlock.pluginsContent, true);
// console.log('lastNode', lastNode);
// console.log('anchorNode', anchorNode);
return anchorNode === lastNode && selection.anchorOffset === lastNode.textContent.length;
}
@ -2785,11 +2791,14 @@ var Keyboard = function (_Module) {
return;
}
event.preventDefault();
/**
* Split the Current Block
*/
this.Editor.BlockManager.split();
if (this.Editor.Caret.isAtEnd) {
/**
* Split the Current Block into two blocks
*/
this.Editor.BlockManager.split();
event.preventDefault();
}
}
/**

File diff suppressed because one or more lines are too long

View file

@ -186,9 +186,9 @@ export default class BlockManager extends Module {
}
/**
*
* @param targetBlock
* @param mergingBlock
* Merge two blocks
* @param {Block} targetBlock - block to merge
* @param {Block} mergingBlock - block that will be merged with target block
*/
mergeBlocks(targetBlock, mergingBlock) {
@ -204,14 +204,18 @@ export default class BlockManager extends Module {
}
let range = document.createRange();
if (mergingBlock.html.textContent.trim() !== '') {
range.selectNodeContents(mergingBlock.pluginsContent);
let range = document.createRange(),
extractedBlock;
let extracted = range.extractContents();
range.selectNodeContents(mergingBlock.pluginsContent);
extractedBlock = range.extractContents();
targetBlock.pluginsContent.appendChild(extracted);
targetBlock.pluginsContent.normalize();
targetBlock.pluginsContent.appendChild(extractedBlock);
targetBlock.pluginsContent.normalize();
}
this.removeBlock(this.currentBlockIndex);

View file

@ -166,7 +166,10 @@ export default class Caret extends Module {
let selection = Selection.get(),
anchorNode = selection.anchorNode,
lastNode = $.getDeepest;
lastNode = $.getDeepestNode(this.Editor.BlockManager.currentBlock.pluginsContent, true);
// console.log('lastNode', lastNode);
// console.log('anchorNode', anchorNode);
return anchorNode === lastNode && selection.anchorOffset === lastNode.textContent.length;

View file

@ -94,11 +94,15 @@ export default class Keyboard extends Module {
}
event.preventDefault();
/**
* Split the Current Block
*/
this.Editor.BlockManager.split();
if (this.Editor.Caret.isAtEnd) {
/**
* Split the Current Block into two blocks
*/
this.Editor.BlockManager.split();
event.preventDefault();
}
}