fix tree walker

This commit is contained in:
Peter Savchenko 2018-05-29 18:59:32 +03:00
commit 5c08edae77
No known key found for this signature in database
GPG key ID: 63E739583C761566
4 changed files with 32 additions and 25 deletions

View file

@ -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

View file

@ -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);
}
}

View file

@ -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;