W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2010

[whatwg] Request for new DOM property textarea.selectionText

From: Biju <bijumaillist@gmail.com>
Date: Mon, 10 May 2010 03:59:00 -0400
Message-ID: <AANLkTinFcffemAo94FCkOwPdYq_DX2gi1e_Z_ZpLtCKt@mail.gmail.com>
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
Received on Monday, 10 May 2010 00:59:00 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:23 UTC