guardian / scribe

DEPRECATED: A rich text editor framework for the web platform

Home Page:http://guardian.github.io/scribe/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node.length?

mindplay-dk opened this issue · comments

What's this?

https://github.com/guardian/scribe/blob/master/src/plugins/core/inline-elements-mode.js#L12

Nodes do not have a .length property, so most likely that part of the expression simply evaluates as false in every case.

What was this part of the expression intended to accomplish?

My guess would be that this is meant to be a check on the childNodes length.

@OliverJAsh I don't suppose you can recall what this condition was aiming to do can you?

I don't remember writing that! Sorry that's not very helpful…

Well, the comment says "If the node is a non-empty element or has content", so that explains the intent. Except this wouldn't work, and one wonders if it should work that way or not?

I'd suggest de-obfuscating that curious use of Array.indexOf and the binary ~ operator as well.

So probably:

        if (treeWalker.currentNode.nodeName === "BR" || treeWalker.currentNode.children > 0) {
          return true; // If the node is a non-empty element or has content
        }

(probably this function should be given a name though, and moved into node.js with the other helpers, and have a test.)