W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2011

[whatwg] Control over selection direction

From: Ojan Vafai <ojan@chromium.org>
Date: Wed, 12 Jan 2011 11:59:20 -0800
Message-ID: <AANLkTim8CWM9ADzo5StYEdA7e0tF3ZkYxpgQWSNDT-qy@mail.gmail.com>
I agree that something like this is a valuable addition. I'm not sure
selectionAnchor is ideal. I was thinking
selectionDirection="forward"/"backward". It's equivalent really, but that
just seems more intuitive to me.

On Wed, Jan 12, 2011 at 11:35 AM, Marijn Haverbeke <marijnh at gmail.com>wrote:

> Hi,
>
> I'd like to propose a minor addition to 4.10.20 APIs for the text
> field selections. When programmatically setting the selection of a
> text input, it is currently impossible to create a range with the
> 'anchor' at the bottom and the 'base' at the top. Concretely, this
> means that, after a selection has been set by a program, if the user
> presses shift and moves the cursor, it is always the bottom of the
> selection that is moved. When doing heavy scripting on such input
> element, it is often necessary to restore a previous selection exactly
> as the user made it. This is currently not possible, and I'd say the
> HTML5 standard is our only hope of finally getting something like this
> widely implemented.
>
> The most obvious way to handle this would be to allow selectionStart
> to be greater than selectionEnd. This is, however, unacceptable for
> various reasons -- it's not easily feature-detectable, it breaks older
> code that reads these properties and expects start to never be greater
> than end, and it makes the names more confusing than they have to be.
>
> So I propose a selectionAnchor property, which holds either "top" or
> "bottom", and can be set to one of these strings to modify the
> direction. "top" would mean the anchor lies after the base of the
> selection, so further shift-movement modifies the bottom, whereas
> "botton" means the inverse, with movement modifying the top. (I think
> the "top"/"bottom" terminology shouldn't break with any languages that
> order characters differently. Does anyone write bottom to top? If
> someone sees a problem, we could choose other terms, but these are the
> most obvious I could come up with.)
>
> So, in standard-ese:
>
> -----
>
> element.selectionAnchor [= value]
>
> Returns either "top" or "bottom", indicating the side of the selection
> that is anchored.
>
> Can be set to change the side of the selection that counts as the anchor.
>
> [...]
>
> The selectionAnchor attribute must, on getting, return one of the
> strings "top" or "bottom". "bottom" is returned when the anchor, the
> fixed end, of the selection lies before the base, the movable end.
> "top" is returned in all other cases.
>
> When set to "top" when its current value is "bottom", or set to
> "bottom" when its current value is "top", is must flip the roles of
> the ends of the selection, so that what used to be the anchor now
> becomes the base. When set to any other value, this is ignored.
>
> ------
>
> Let me know what you think.
>
> Best,
> Marijn Haverbeke
>
Received on Wednesday, 12 January 2011 11:59:20 UTC

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