mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 23:55:49 +01:00
fix tree walker
This commit is contained in:
parent
beeecba089
commit
5c08edae77
4 changed files with 32 additions and 25 deletions
|
|
@ -693,8 +693,6 @@ var Dom = function () {
|
|||
var treeWalker = [],
|
||||
leafs = [];
|
||||
|
||||
console.warn('check', node);
|
||||
|
||||
if (!node) {
|
||||
|
||||
return true;
|
||||
|
|
@ -705,10 +703,14 @@ var Dom = function () {
|
|||
return this.isNodeEmpty(node);
|
||||
}
|
||||
|
||||
treeWalker.push(node);
|
||||
treeWalker.push(node.firstChild);
|
||||
|
||||
while (treeWalker.length > 0) {
|
||||
|
||||
node = treeWalker.shift();
|
||||
|
||||
if (!node) continue;
|
||||
|
||||
if (this.isLeaf(node)) {
|
||||
|
||||
leafs.push(node);
|
||||
|
|
@ -728,17 +730,13 @@ var Dom = function () {
|
|||
*/
|
||||
if (node && !this.isNodeEmpty(node)) {
|
||||
|
||||
console.log('NOT EMPTY!!!!!!!!!', node);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
node = treeWalker.shift();
|
||||
if (node.firstChild) {
|
||||
|
||||
if (!node) continue;
|
||||
|
||||
node = node.firstChild;
|
||||
treeWalker.push(node);
|
||||
treeWalker.push(node.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
return leafs.every(function (leaf) {
|
||||
|
|
@ -2683,9 +2681,14 @@ var Caret = function (_Module) {
|
|||
return $.isEmpty(node);
|
||||
});
|
||||
|
||||
console.log('nothing at left?', nothingAtLeft);
|
||||
/**
|
||||
* Workaround case when caret in the text link " |Hello!"
|
||||
* selection.anchorOffset is 1, but real caret visible position is 0
|
||||
* @type {number}
|
||||
*/
|
||||
var firstLetterPosition = anchorNode.textContent.search(/\S/);
|
||||
|
||||
if (nothingAtLeft && selection.anchorOffset === 0) {
|
||||
if (nothingAtLeft && selection.anchorOffset === firstLetterPosition) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -258,8 +258,6 @@ export default class Dom {
|
|||
let treeWalker = [],
|
||||
leafs = [];
|
||||
|
||||
console.warn('check', node);
|
||||
|
||||
if (!node) {
|
||||
|
||||
return true;
|
||||
|
|
@ -272,10 +270,14 @@ export default class Dom {
|
|||
|
||||
}
|
||||
|
||||
treeWalker.push(node);
|
||||
treeWalker.push(node.firstChild);
|
||||
|
||||
while ( treeWalker.length > 0 ) {
|
||||
|
||||
node = treeWalker.shift();
|
||||
|
||||
if (!node) continue;
|
||||
|
||||
if ( this.isLeaf(node) ) {
|
||||
|
||||
leafs.push(node);
|
||||
|
|
@ -297,18 +299,15 @@ export default class Dom {
|
|||
*/
|
||||
if (node && !this.isNodeEmpty(node)) {
|
||||
|
||||
console.log('NOT EMPTY!!!!!!!!!', node);
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
node = treeWalker.shift();
|
||||
if ( node.firstChild ) {
|
||||
|
||||
if (!node) continue;
|
||||
treeWalker.push(node.firstChild);
|
||||
|
||||
node = node.firstChild;
|
||||
treeWalker.push(node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -226,9 +226,14 @@ export default class Caret extends Module {
|
|||
let leftSiblings = this.getHigherLevelSiblings(anchorNode, 'left'),
|
||||
nothingAtLeft = leftSiblings.every( node => $.isEmpty(node) );
|
||||
|
||||
console.log('nothing at left?', nothingAtLeft);
|
||||
/**
|
||||
* Workaround case when caret in the text link " |Hello!"
|
||||
* selection.anchorOffset is 1, but real caret visible position is 0
|
||||
* @type {number}
|
||||
*/
|
||||
let firstLetterPosition = anchorNode.textContent.search(/\S/);
|
||||
|
||||
if (nothingAtLeft && selection.anchorOffset === 0) {
|
||||
if (nothingAtLeft && selection.anchorOffset === firstLetterPosition) {
|
||||
|
||||
return true;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue