[whatwg] [editing] Caret Position Access Methods

Ehsan Akhgari ehsan at mozilla.com
Wed Aug 10 16:39:53 PDT 2011


On 11-07-29 2:14 PM, Ryosuke Niwa wrote:
> On Fri, Jul 29, 2011 at 11:07 AM, Dan Gisolfi<gisolfi at us.ibm.com>  wrote:
>>
>> My point herein and motivation for the suggestion is that this
>> functionality (get/set caret) is available in the textarea element. Using
>> a textarea element you can get/set caret position via
>> get/setSelectionRange(). These two methods should be implemented for a
>> contentEditable div or the likes. Within a contentEditable div, there is
>> no way to [a] tell where the caret is in relation to the text, such as the
>> index; [b] direct the caret to a specific position within the text.
>>
>
> So what you want is Range/Selection<->  TextIndex API?  I think that makes a
> sense.  Ideally such an API provide an index of selection/range within the
> textContent of the editing host.  WebKit already implements very similar
> mechanism internally and use it extensively in editing, spell checking, and
> IME code.

I think I may be missing something.  Aren't ranges exactly what you 
want?  It would be very nice to enable execCommand to work on any given 
range, but besides that, I don't see why we need to modify the selection 
spec at all...

Ehsan


More information about the whatwg mailing list