[whatwg/dom] Improvements for adjacent text nodes manipulation (#335)

Dropping here a couple of things I would like to have in DOM.

While I like that contiguous text nodes can be used as separated entities, e.g. for setting their contents without touching their surrounding text siblings, I think something more could be done for when creating adjacent text nodes is not intentional.

First of all, the problem with `normalize()`: it's impossible to normalize a sequence of text nodes only without touching others in the same parent element:

```
running div.normalize(); will merge both sequences
<div>
      first text node       <- I only want
      second text node      <- these two merged
      <span></span>
      first text node       <- While these must stay
      second text node      <- two distinct text nodes
</div>
```

## Suggested additions to Text:

### `Text.prototype.getFirstNearbyText = function(skipComments){};`
Selects the first Text node in a sequence of contiguous Text nodes.
`this` is any of the Text nodes in the sequence.
`skipComments = true` would make the algorithm ignore `<!-- comments -->` between text nodes. 

### `Text.prototype.getLastNearbyText = function(skipComments){};`
Like previous, but selects the last Text node in the contiguous Text nodes sequence.

### `Text.prototype.getNearbyTextString = function(skipComments){};`
Same purpose of `textNode.wholeText ` except that it allows to jump around comment nodes if arg0 is true. `textNode.wholeText === textNode.getNearbyTextString(false)`. Returns a `DOMString`.

### `Text.prototype.mergeNearbyText = function(eatComments){};`
Replaces this Text node's nearby Text siblings with a new single Text node containing said siblings' concatenation of DOMStrings.

Thoughts?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/335

Received on Saturday, 1 October 2016 02:14:06 UTC