[whatwg] Making selectionDirection platform-independent

Ryosuke Niwa rniwa at webkit.org
Mon Sep 26 09:34:27 PDT 2011


On Mon, Sep 26, 2011 at 9:14 AM, Philip Rogers <pdr at google.com> wrote:

> The spec (
>
> http://www.whatwg.org/specs/web-apps/current-work/#dom-textarea/input-selectiondirection
> )
> currently allows for platform-specific differences in selectionDirection
> that limit its usefulness. Tightening the requirements to be
> platform-independent will allow selectionDirection to be used for
> determining the caret location in a selection.
>

No. The property is platform dependent. It's just that UAs on Windows and
Linux don't use "none" in most cases.

On Windows, selectionDirection indicates which end of the selection the
> caret should be placed. On Mac, selectionDirection works similarly when the
> selection is modified using shift+arrow key, but the spec does not require
> the same functionality when clicking and dragging a selection.


Yes, but this is required to match Mac's native selection behavior. Always
giving direction to selection is neither desirable nor feasible at least in
WebKit. A directionless selection allows users to extend it to either
direction.

e.g. say we have a directionless selection on "r" in "world". Then pressing
left-arrow key results in selecting "or" and pressing right arrow key
results in selecting "rl".

This leaves no cross-platform way to determine the correct caret location!

It looks like editors using a textarea (such as codemirror) are currently
> working

around this by not drawing a cursor when there is a selection.


We can't assume that the caret is always rendered on either side since
the caret is never rendered with a range selection (not collapsed) on Mac.


> Are there arguments against making selectionDirection explicitly "forward"
> or "backward" if the user modifies the selection, regardless of platform?
>

Yes. See above.

- Ryosuke



More information about the whatwg mailing list