[whatwg] Request for new DOM property textarea.selectionText

Biju bijumaillist at gmail.com
Mon May 10 00:59:00 PDT 2010


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



More information about the whatwg mailing list