[whatwg] Standard method to get/set caret position

martijn martijnw at hotpop.com
Mon Aug 30 10:36:42 PDT 2004


Ian Hickson wrote:

>I was going to add an IE-compatible version of this to the Web Forms spec 
>but I honestly couldn't work out how it worked. I read almost every MSDN 
>reference page on document.selection. textRange, and related APIs, and all 
>I got out of it was a minor headache.
>
>Sadly the Mozilla APIs you used in your example aren't perfect either -- 
>the cursor could be at either selectionStart or selectionEnd, you don't 
>really have a way of knowing.
>  
>
It seems to me that the selection is the position of the cursor, not? 
When you press the left arrow key, the selection collapses and the 
cursor is at the start of where the selection was. With the right arrow 
key, the selection collapses and the cursor is at the end of where the 
selection was. Why should there also be a caret?
Imho, the caret is just a collapsed selection which happens to be 
blinking (otherwise it would be not very visible).

>DOM Range could be used to define the selection of the document but that 
>wouldn't work for selections in input and textarea elements since those 
>don't have DOM nodes they correspond to. We could define that they do but 
>that's quite a big change.
>
>  
>
I would certainly be in favor of that, because I like the range document 
object model. I think the change that would be necessary is that typing 
text inside text inputs and textareas  should change the corresponding 
value attribute and for the textarea the textnode inside the textarea.

>Mozilla's window.getSelection() method doesn't actually return a DOM 
>Range, it returns some custom interface.
>
>  
>
Yes, it holds a collection of all the ranges you have added to the 
selection object. so i't possible to have multiple selections in one 
document.

>So I don't know. What do people think? Should we try to be backards 
>compatible with the Mozilla interface or the IE interface, or should we 
>start from scratch here, and require that people write wrappers around 
>the Moz and IE wrappers if they want compatibility? If we use something 
>already defined, what do we use? What are the use cases that matter?
>  
>
I'm in favor of the Mozilla interface.

-Martijn



More information about the whatwg mailing list