[whatwg] Request for new DOM property textarea.selectionText

Ryosuke Niwa rniwa at webkit.org
Mon Apr 30 23:17:49 PDT 2012


On Mon, Apr 30, 2012 at 11:01 PM, Ian Hickson <ian at hixie.ch> wrote:

> On Mon, 30 Apr 2012, Ojan Vafai wrote:
> > I'd also like to see us expose a method for getting the text that
> > accepts optional start/end arguments. Mainly, this allows for the
> > possibility of browser vendors to performance optimize (e.g. don't need
> > to convert the whole string to a JS string just to get the 5 selected
> > characters out).
>
> Is that really that expensive? Seems like it'd be better just to have UAs
> optimise their JS string implementations so that it can just be backed by
> the same thing as the DOM or the control's editor. (I believe Mozilla may
> in fact already do that.)
>

In theory, this is possible. But any sort of proxy, etc... that lazily
obtain the value (e.g. delaying it until substr, etc... is called) is hard
to implement in practice because we need to serialize text before DOM is
modified. e.g.

1 var inputValue = input.value;
2 var textUsed = input.value.substr(5, 10);

In the above example, inputValue could be a proxy object. However, in the
example below:

1 var inputValue = input.value;
2 input.value = 'bar';
3 var textUsed = input.value.substr(5, 10);

we need to serialize the string immediately before the statement in the
line 2 is evaluated.

- Ryosuke



More information about the whatwg mailing list