mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Issue was incorrect filter param in createTreeWalker
This commit is contained in:
parent
48769f0aca
commit
8a8d64a2c1
1 changed files with 18 additions and 13 deletions
31
vendors/squire/build/squire-raw.js
vendored
31
vendors/squire/build/squire-raw.js
vendored
|
|
@ -107,8 +107,12 @@ const
|
||||||
isInline = node => getNodeCategory( node ) === INLINE,
|
isInline = node => getNodeCategory( node ) === INLINE,
|
||||||
isBlock = node => getNodeCategory( node ) === BLOCK,
|
isBlock = node => getNodeCategory( node ) === BLOCK,
|
||||||
isContainer = node => getNodeCategory( node ) === CONTAINER,
|
isContainer = node => getNodeCategory( node ) === CONTAINER,
|
||||||
|
createTreeWalker = (root, whatToShow, filter) => doc.createTreeWalker( root, whatToShow, filter ? {
|
||||||
|
acceptNode: node => filter(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
||||||
|
} : null
|
||||||
|
),
|
||||||
getBlockWalker = ( node, root ) => {
|
getBlockWalker = ( node, root ) => {
|
||||||
let walker = doc.createTreeWalker( root, SHOW_ELEMENT, isBlock );
|
let walker = createTreeWalker( root, SHOW_ELEMENT, isBlock );
|
||||||
walker.currentNode = node;
|
walker.currentNode = node;
|
||||||
return walker;
|
return walker;
|
||||||
},
|
},
|
||||||
|
|
@ -282,6 +286,7 @@ const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// } else if ( !node.querySelector( 'BR' ) ) {
|
// } else if ( !node.querySelector( 'BR' ) ) {
|
||||||
|
// } else if ( !node.innerText.trim().length ) {
|
||||||
} else if ( node.matches( ':empty' ) ) {
|
} else if ( node.matches( ':empty' ) ) {
|
||||||
fixer = createElement( 'BR' );
|
fixer = createElement( 'BR' );
|
||||||
while ( ( child = node.lastElementChild ) && !isInline( child ) ) {
|
while ( ( child = node.lastElementChild ) && !isInline( child ) ) {
|
||||||
|
|
@ -1035,7 +1040,7 @@ const
|
||||||
return block && isNodeContainedInRange( range, block ) ? block : null;
|
return block && isNodeContainedInRange( range, block ) ? block : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
newContentWalker = root => doc.createTreeWalker( root,
|
newContentWalker = root => createTreeWalker( root,
|
||||||
SHOW_TEXT|SHOW_ELEMENT,
|
SHOW_TEXT|SHOW_ELEMENT,
|
||||||
node => node.nodeType === TEXT_NODE ? notWS.test( node.data ) : node.nodeName === 'IMG'
|
node => node.nodeType === TEXT_NODE ? notWS.test( node.data ) : node.nodeName === 'IMG'
|
||||||
),
|
),
|
||||||
|
|
@ -1858,7 +1863,7 @@ let cleanTree = ( node, config, preserveWS ) => {
|
||||||
while ( isInline( nonInlineParent ) ) {
|
while ( isInline( nonInlineParent ) ) {
|
||||||
nonInlineParent = nonInlineParent.parentNode;
|
nonInlineParent = nonInlineParent.parentNode;
|
||||||
}
|
}
|
||||||
let walker = doc.createTreeWalker( nonInlineParent, SHOW_TEXT|SHOW_ELEMENT );
|
let walker = createTreeWalker( nonInlineParent, SHOW_TEXT|SHOW_ELEMENT );
|
||||||
|
|
||||||
for ( i = 0, l = children.length; i < l; ++i ) {
|
for ( i = 0, l = children.length; i < l; ++i ) {
|
||||||
child = children[i];
|
child = children[i];
|
||||||
|
|
@ -1966,7 +1971,7 @@ let isLineBreak = ( br, isLBIfEmptyBlock ) => {
|
||||||
while ( isInline( block ) ) {
|
while ( isInline( block ) ) {
|
||||||
block = block.parentNode;
|
block = block.parentNode;
|
||||||
}
|
}
|
||||||
walker = doc.createTreeWalker( block, SHOW_ELEMENT|SHOW_TEXT, notWSTextNode );
|
walker = createTreeWalker( block, SHOW_ELEMENT|SHOW_TEXT, notWSTextNode );
|
||||||
walker.currentNode = br;
|
walker.currentNode = br;
|
||||||
return !!walker.nextNode() ||
|
return !!walker.nextNode() ||
|
||||||
( isLBIfEmptyBlock && !walker.previousNode() );
|
( isLBIfEmptyBlock && !walker.previousNode() );
|
||||||
|
|
@ -2715,7 +2720,7 @@ proto.getSelectedText = function () {
|
||||||
if ( !range || range.collapsed ) {
|
if ( !range || range.collapsed ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
let walker = doc.createTreeWalker(
|
let walker = createTreeWalker(
|
||||||
range.commonAncestorContainer,
|
range.commonAncestorContainer,
|
||||||
SHOW_TEXT|SHOW_ELEMENT,
|
SHOW_TEXT|SHOW_ELEMENT,
|
||||||
node => isNodeContainedInRange( range, node )
|
node => isNodeContainedInRange( range, node )
|
||||||
|
|
@ -2768,7 +2773,7 @@ proto.getPath = function () {
|
||||||
// the bottom of the tree so the block can be selected. Define that node as the
|
// the bottom of the tree so the block can be selected. Define that node as the
|
||||||
// keepNode.
|
// keepNode.
|
||||||
let removeZWS = ( root, keepNode ) => {
|
let removeZWS = ( root, keepNode ) => {
|
||||||
let walker = doc.createTreeWalker( root, SHOW_TEXT );
|
let walker = createTreeWalker( root, SHOW_TEXT );
|
||||||
let parent, node, index;
|
let parent, node, index;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 &&
|
while ( ( index = node.data.indexOf( ZWS ) ) > -1 &&
|
||||||
|
|
@ -3101,7 +3106,7 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
||||||
|
|
||||||
// Otherwise, check each text node at least partially contained within
|
// Otherwise, check each text node at least partially contained within
|
||||||
// the selection and make sure all of them have the format we want.
|
// the selection and make sure all of them have the format we want.
|
||||||
walker = doc.createTreeWalker( common, SHOW_TEXT, node => isNodeContainedInRange( range, node ) );
|
walker = createTreeWalker( common, SHOW_TEXT, node => isNodeContainedInRange( range, node ) );
|
||||||
|
|
||||||
let seenNode = false;
|
let seenNode = false;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
|
|
@ -3197,7 +3202,7 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
//
|
//
|
||||||
// IMG tags are included because we may want to create a link around
|
// IMG tags are included because we may want to create a link around
|
||||||
// them, and adding other styles is harmless.
|
// them, and adding other styles is harmless.
|
||||||
walker = doc.createTreeWalker(
|
walker = createTreeWalker(
|
||||||
range.commonAncestorContainer,
|
range.commonAncestorContainer,
|
||||||
SHOW_TEXT|SHOW_ELEMENT,
|
SHOW_TEXT|SHOW_ELEMENT,
|
||||||
node => ( node.nodeType === TEXT_NODE ||
|
node => ( node.nodeType === TEXT_NODE ||
|
||||||
|
|
@ -3797,8 +3802,8 @@ proto.setHTML = function ( html ) {
|
||||||
fixContainer( frag, root );
|
fixContainer( frag, root );
|
||||||
|
|
||||||
// Fix cursor
|
// Fix cursor
|
||||||
let node = frag;
|
let node, walker = getBlockWalker( frag, root );
|
||||||
while ( node = getNextBlock( node, root ) ) {
|
while ( (node = walker.nextNode()) && node !== root ) {
|
||||||
fixCursor( node, root );
|
fixCursor( node, root );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3887,7 +3892,7 @@ proto.insertImage = function ( src, attributes ) {
|
||||||
proto.linkRegExp = /\b(?:((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9][a-z0-9.-]*[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:[^\s?&`!()[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w-]+\.)+[a-z]{2,}\b(?:[?][^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+)*)?))/i;
|
proto.linkRegExp = /\b(?:((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9][a-z0-9.-]*[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:[^\s?&`!()[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w-]+\.)+[a-z]{2,}\b(?:[?][^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+)*)?))/i;
|
||||||
|
|
||||||
let addLinks = ( frag, root, self ) => {
|
let addLinks = ( frag, root, self ) => {
|
||||||
let walker = doc.createTreeWalker( frag, SHOW_TEXT, node => !getClosest( node, root, 'A' ));
|
let walker = createTreeWalker( frag, SHOW_TEXT, node => !getClosest( node, root, 'A' ) );
|
||||||
let linkRegExp = self.linkRegExp;
|
let linkRegExp = self.linkRegExp;
|
||||||
let defaultAttributes = self._config.tagAttributes.a;
|
let defaultAttributes = self._config.tagAttributes.a;
|
||||||
let node, data, parent, match, index, endIndex, child;
|
let node, data, parent, match, index, endIndex, child;
|
||||||
|
|
@ -4265,7 +4270,7 @@ let addPre = function ( frag ) {
|
||||||
output.append( empty( node ) );
|
output.append( empty( node ) );
|
||||||
}
|
}
|
||||||
// 4. Replace nbsp with regular sp
|
// 4. Replace nbsp with regular sp
|
||||||
walker = doc.createTreeWalker( output, SHOW_TEXT );
|
walker = createTreeWalker( output, SHOW_TEXT );
|
||||||
while (( node = walker.nextNode() )) {
|
while (( node = walker.nextNode() )) {
|
||||||
node.data = node.data.replace( NBSP, ' ' ); // nbsp -> sp
|
node.data = node.data.replace( NBSP, ' ' ); // nbsp -> sp
|
||||||
}
|
}
|
||||||
|
|
@ -4283,7 +4288,7 @@ let removePre = function ( frag ) {
|
||||||
let pre, walker, node, value, contents, index;
|
let pre, walker, node, value, contents, index;
|
||||||
while ( l-- ) {
|
while ( l-- ) {
|
||||||
pre = pres[l];
|
pre = pres[l];
|
||||||
walker = doc.createTreeWalker( pre, SHOW_TEXT );
|
walker = createTreeWalker( pre, SHOW_TEXT );
|
||||||
while (( node = walker.nextNode() )) {
|
while (( node = walker.nextNode() )) {
|
||||||
value = node.data;
|
value = node.data;
|
||||||
value = value.replace( / (?= )/g, NBSP ); // sp -> nbsp
|
value = value.replace( / (?= )/g, NBSP ); // sp -> nbsp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue