mirror of
https://github.com/codex-team/editor.js
synced 2026-03-15 23:25:47 +01:00
small improvements
This commit is contained in:
parent
2e6b107bef
commit
ef6f2d5ac3
5 changed files with 51 additions and 49 deletions
|
|
@ -631,19 +631,21 @@ var Dom = function () {
|
|||
key: 'checkNodeEmpty',
|
||||
value: function checkNodeEmpty(node) {
|
||||
|
||||
var nodeText = void 0;
|
||||
|
||||
if (this.isElement(node) && this.isNativeInput(node)) {
|
||||
|
||||
node = node.value;
|
||||
nodeText = node.value;
|
||||
|
||||
if (node.trim()) {
|
||||
if (nodeText.trim()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
nodeText = node.textContent.replace('\u200B', '');
|
||||
|
||||
if (node.trim()) {
|
||||
if (nodeText.trim()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -652,6 +654,24 @@ var Dom = function () {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks node if it is doesn't have child node
|
||||
* @param {Node} node
|
||||
* @return {*|boolean}
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'isLeaf',
|
||||
value: function isLeaf(node) {
|
||||
|
||||
if (!node) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return node.childNodes.length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* breadth-first search
|
||||
*
|
||||
|
|
@ -677,7 +697,7 @@ var Dom = function () {
|
|||
|
||||
while (treeWalker.length > 0) {
|
||||
|
||||
if (node && node.childNodes.length === 0) {
|
||||
if (this.isLeaf(node)) {
|
||||
|
||||
stack.push(node);
|
||||
}
|
||||
|
|
@ -688,11 +708,6 @@ var Dom = function () {
|
|||
|
||||
if (!node) continue;
|
||||
|
||||
if (node.childNodes.length === 0) {
|
||||
|
||||
stack.push(node);
|
||||
}
|
||||
|
||||
treeWalker.push(node);
|
||||
}
|
||||
|
||||
|
|
@ -1711,23 +1726,17 @@ var BlockManager = function (_Module) {
|
|||
lastTextNode = $.getDeepestTextNode(currentBlock.pluginsContent, true),
|
||||
textNodeLength = lastTextNode.length;
|
||||
|
||||
console.log('here right');
|
||||
console.log(_Selection2.default.getSelectionAnchorNode());
|
||||
console.log(lastTextNode);
|
||||
|
||||
if (_Selection2.default.getSelectionAnchorNode() !== lastTextNode) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(lastTextNode);
|
||||
if (_Selection2.default.getSelectionAnchorOffset() === textNodeLength) {
|
||||
|
||||
var nextBlock = this.getNextBlock();
|
||||
|
||||
if (!nextBlock) return;
|
||||
|
||||
// this.currentNode = nextBlock.pluginsContent;
|
||||
this.Editor.Caret.set(nextBlock.pluginsContent);
|
||||
}
|
||||
}
|
||||
|
|
@ -1739,10 +1748,6 @@ var BlockManager = function (_Module) {
|
|||
firstTextNode = $.getDeepestTextNode(currentBlock.pluginsContent, false),
|
||||
textNodeLength = firstTextNode.length;
|
||||
|
||||
console.log('here left');
|
||||
console.log(_Selection2.default.getSelectionAnchorNode());
|
||||
console.log(firstTextNode);
|
||||
|
||||
if (_Selection2.default.getSelectionAnchorNode() !== firstTextNode) {
|
||||
|
||||
return;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -84,12 +84,6 @@
|
|||
data : {
|
||||
text : '<span><textarea></textarea></span><p><b></b></p><strong></strong><i><span></span></i>'
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'text',
|
||||
data : {
|
||||
text: 'sdfsdfsd'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export default class Dom {
|
|||
*/
|
||||
static make(tagName, classNames = null, attributes = {}) {
|
||||
|
||||
var el = document.createElement(tagName);
|
||||
let el = document.createElement(tagName);
|
||||
|
||||
if ( Array.isArray(classNames) ) {
|
||||
|
||||
|
|
@ -184,11 +184,13 @@ export default class Dom {
|
|||
*/
|
||||
static checkNodeEmpty(node) {
|
||||
|
||||
let nodeText;
|
||||
|
||||
if ( this.isElement(node) && this.isNativeInput(node) ) {
|
||||
|
||||
node = node.value;
|
||||
nodeText = node.value;
|
||||
|
||||
if ( node.trim() ) {
|
||||
if ( nodeText.trim() ) {
|
||||
|
||||
return false;
|
||||
|
||||
|
|
@ -197,9 +199,9 @@ export default class Dom {
|
|||
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
nodeText = node.textContent.replace('\u200B', '');
|
||||
|
||||
if ( node.trim() ) {
|
||||
if ( nodeText.trim() ) {
|
||||
|
||||
return false;
|
||||
|
||||
|
|
@ -211,6 +213,23 @@ export default class Dom {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks node if it is doesn't have child node
|
||||
* @param {Node} node
|
||||
* @return {*|boolean}
|
||||
*/
|
||||
static isLeaf(node) {
|
||||
|
||||
if (!node) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return node.childNodes.length === 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* breadth-first search
|
||||
*
|
||||
|
|
@ -233,7 +252,7 @@ export default class Dom {
|
|||
|
||||
while ( treeWalker.length > 0 ) {
|
||||
|
||||
if (node && node.childNodes.length === 0) {
|
||||
if ( this.isLeaf(node) ) {
|
||||
|
||||
stack.push(node);
|
||||
|
||||
|
|
@ -245,12 +264,6 @@ export default class Dom {
|
|||
|
||||
if (!node) continue;
|
||||
|
||||
if (node.childNodes.length === 0) {
|
||||
|
||||
stack.push(node);
|
||||
|
||||
}
|
||||
|
||||
treeWalker.push(node);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,24 +159,18 @@ export default class BlockManager extends Module {
|
|||
lastTextNode = $.getDeepestTextNode(currentBlock.pluginsContent, true),
|
||||
textNodeLength = lastTextNode.length;
|
||||
|
||||
console.log('here right');
|
||||
console.log(Selection.getSelectionAnchorNode());
|
||||
console.log(lastTextNode);
|
||||
|
||||
if (Selection.getSelectionAnchorNode() !== lastTextNode) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
console.log(lastTextNode);
|
||||
if (Selection.getSelectionAnchorOffset() === textNodeLength) {
|
||||
|
||||
let nextBlock = this.getNextBlock();
|
||||
|
||||
if (!nextBlock) return;
|
||||
|
||||
// this.currentNode = nextBlock.pluginsContent;
|
||||
this.Editor.Caret.set( nextBlock.pluginsContent );
|
||||
|
||||
}
|
||||
|
|
@ -189,10 +183,6 @@ export default class BlockManager extends Module {
|
|||
firstTextNode = $.getDeepestTextNode(currentBlock.pluginsContent, false),
|
||||
textNodeLength = firstTextNode.length;
|
||||
|
||||
console.log('here left');
|
||||
console.log(Selection.getSelectionAnchorNode());
|
||||
console.log(firstTextNode);
|
||||
|
||||
if (Selection.getSelectionAnchorNode() !== firstTextNode) {
|
||||
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue