fix merging

This commit is contained in:
Murod Khaydarov 2018-05-22 16:52:11 +03:00
commit d2470fe44d
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
6 changed files with 29 additions and 29 deletions

View file

@ -545,13 +545,9 @@ var Dom = function () {
if (node && node.nodeType === Node.ELEMENT_NODE && node.firstChild) {
if (atLast) {
var nodeChild = atLast ? node.lastChild : node.firstChild;
return this.getDeepestNode(node.lastChild, atLast);
} else {
return this.getDeepestNode(node.firstChild, false);
}
return this.getDeepestNode(nodeChild, atLast);
}
return node;
@ -1555,11 +1551,16 @@ var BlockManager = function (_Module) {
mergingBlock = this._blocks[this.currentBlockIndex];
}
if (mergingBlock.html.textContent.trim() !== '') {
if (!$.isEmpty(mergingBlock.html)) {
var range = document.createRange(),
var selection = _Selection2.default.get(),
selectRange = selection.getRangeAt(0),
extractedBlock = void 0;
selectRange.deleteContents();
var range = selectRange.cloneRange(true);
range.selectNodeContents(mergingBlock.pluginsContent);
extractedBlock = range.extractContents();
@ -1584,6 +1585,8 @@ var BlockManager = function (_Module) {
// decrease current block index so that to know current actual
this.currentBlockIndex--;
this.currentNode = this._blocks[this.currentBlockIndex].html;
// set caret to the block without offset at the end
this.Editor.Caret.setToBlock(this.currentBlock, 0, true);
this.Editor.Toolbar.close();
@ -1923,11 +1926,12 @@ var Blocks = function () {
key: 'remove',
value: function remove(index) {
if (!isNaN(index)) {
if (!index) {
index = this.length - 1;
}
// this.blocks[index].html;
this.blocks[index].html.remove();
this.blocks.splice(index, 1);
}
@ -2548,9 +2552,6 @@ var Caret = function (_Module) {
anchorNode = selection.anchorNode,
lastNode = $.getDeepestNode(this.Editor.BlockManager.currentBlock.pluginsContent, true);
// console.log('lastNode', lastNode);
// console.log('anchorNode', anchorNode);
return anchorNode === lastNode && selection.anchorOffset === lastNode.textContent.length;
}
}]);
@ -2810,7 +2811,7 @@ var Keyboard = function (_Module) {
key: 'backSpacePressed',
value: function backSpacePressed(event) {
if (this.Editor.Caret.isAtStart) {
if (this.Editor.Caret.isAtStart && this.Editor.BlockManager.currentBlockIndex !== 0) {
this.Editor.BlockManager.mergeBlocks();
event.preventDefault();

File diff suppressed because one or more lines are too long

View file

@ -111,15 +111,9 @@ export default class Dom {
if (node && node.nodeType === Node.ELEMENT_NODE && node.firstChild) {
if (atLast) {
let nodeChild = atLast ? node.lastChild : node.firstChild;
return this.getDeepestNode(node.lastChild, atLast);
} else {
return this.getDeepestNode(node.firstChild, false);
}
return this.getDeepestNode(nodeChild, atLast);
}

View file

@ -204,11 +204,16 @@ export default class BlockManager extends Module {
}
if (mergingBlock.html.textContent.trim() !== '') {
if (!$.isEmpty(mergingBlock.html)) {
let range = document.createRange(),
let selection = Selection.get(),
selectRange = selection.getRangeAt(0),
extractedBlock;
selectRange.deleteContents();
let range = selectRange.cloneRange(true);
range.selectNodeContents(mergingBlock.pluginsContent);
extractedBlock = range.extractContents();
@ -232,6 +237,8 @@ export default class BlockManager extends Module {
// decrease current block index so that to know current actual
this.currentBlockIndex--;
this.currentNode = this._blocks[this.currentBlockIndex].html;
// set caret to the block without offset at the end
this.Editor.Caret.setToBlock(this.currentBlock, 0, true);
this.Editor.Toolbar.close();
@ -542,12 +549,13 @@ class Blocks {
*/
remove(index) {
if (!isNaN(index)) {
if (!index) {
index = this.length - 1;
}
// this.blocks[index].html;
this.blocks[index].html.remove();
this.blocks.splice(index, 1);

View file

@ -168,9 +168,6 @@ export default class Caret extends Module {
anchorNode = selection.anchorNode,
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

@ -112,7 +112,7 @@ export default class Keyboard extends Module {
*/
backSpacePressed(event) {
if (this.Editor.Caret.isAtStart) {
if (this.Editor.Caret.isAtStart && this.Editor.BlockManager.currentBlockIndex !== 0) {
this.Editor.BlockManager.mergeBlocks();
event.preventDefault();