[whatwg] Request for new DOM property textarea.selectionText

In addition to selection and scroll issues, needing to replace the entire
textarea value doesn't scale and thus limits what sorts of things you can do
with textareas. A general way to set a sub-part of a textarea's value seems
useful to me. I don't think we should tie that to setting the selected text
though.

textarea.setRangeText(start, end, text);

It replaces the text between start and end, maintains current scroll
position and preserves the selection.

Ojan

On Mon, May 10, 2010 at 12:59 AM, Biju <bijumaillist at gmail.com> wrote:

> Current way in firefox is to
>
> 1. OrigStart = textarea.selectionStart
> 2.  textarea.value = textarea.value.substr(0, OrigStart)
>                          + new_text_to_replace
>                          + textarea.value.substr(textarea.selectionEnd);
> 3. Now u loose original selection, so
>
> 4.  textarea.setSelectionRange(OrigStart,
>  OrigStart+new_text_to_replace.length)
> 5.  remember .scrollTop and reapply if needed
>
> Now if we are only changing few selected characters in TEXTAREA with
> big text content,
> we are unnecessarily replacing entire content, which is inefficient.
>
>
> On IE even though wierd you can do it simply by
>   document.selection.createRange().text = new_text_to_replace;
> BTW, you need to make sure the selection is currently on the
> textarea/input form control.
> IE is also very fast when doing that, when firefox hangs few second
> using the other way
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20100510/fb9d66da/attachment.htm>

Received on Monday, 10 May 2010 07:27:23 UTC