This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 11745 - Feature request: element.replaceSelection(str) for text fields
Summary: Feature request: element.replaceSelection(str) for text fields
Alias: None
Product: HTML WG
Classification: Unclassified
Component: LC1 HTML5 spec (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
Depends on:
Reported: 2011-01-13 00:23 UTC by contributor
Modified: 2011-08-04 05:03 UTC (History)
5 users (show)

See Also:


Description contributor 2011-01-13 00:23:57 UTC

Feature request: element.replaceSelection(str) should change the text field's
value by replacing the current selection with the provided string, which
should then be the new selection.  This is apparently supported well in IE's
proprietary equivalent, and a MediaWiki developer pointed it out as one of the
significant problems he ran into with the standard approach:
eature_requests#Changing_the_text_contents_of_a_range I think this is simple
enough to spec before implementation, if implementers are interested, to avoid
the whole vendor prefix rigamarole.

Posted from:
Comment 1 Ian 'Hixie' Hickson 2011-02-15 00:26:43 UTC
Aryeh: Is there an API for this kind of thing already, by any chance?
Comment 2 Aryeh Gregor 2011-02-15 18:34:38 UTC
If there was an API, I wouldn't have filed this bug.  :)  With DOM Range, you should be able to emulate it pretty easily via deleteContents() and insertNode(), although that's not specced and I haven't tried it.  But for textbox/input selections, which are different because their contents aren't in the DOM, there's no standard API to do this.

Looking back at this issue, though, I'm not sure this is necessary, and if it is necessary not sure it's the right way to fix it.  Browsers could make it more efficient as it stands, namely make

input.value = input.value.substr(0, input.selectionStart) + someText + input.value.substr(input.selectionEnd);

more efficient somehow for large input values.  And if that's not the right approach, I don't think it actually makes sense to tie this to the user's selection -- maybe you want to replace some slice for some other reason.

So I'm going to resolve INVALID, on reflection.  We probably have better things to do.  If there are performance problems with existing browsers, bugs should be filed on them, and we can consider new features if they think that's the best way to solve the problem.
Comment 3 Michael[tm] Smith 2011-08-04 05:03:37 UTC
mass-moved component to LC1