mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 07:35:48 +01:00
fix merging
This commit is contained in:
parent
7c7f978e61
commit
d2470fe44d
6 changed files with 29 additions and 29 deletions
|
|
@ -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
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue