w3c / selection-api

Selection API
http://w3c.github.io/selection-api/
Other
47 stars 30 forks source link

Expose with which bidi-level caret is affiliated as well as API to set it #57

Open rniwa opened 9 years ago

rniwa commented 9 years ago

We need to expose information as to which bidi-level (LTR or RTL or both) the caret is associated with visually, as well as an API to specify it (e.g. add an optional argument to setPosition and collapse).

Also see issues #32 and #51.

yosinch commented 7 years ago

I support this idea. Can we unify this to beforeLineWrap#32?

In Blink/WebKit, there is TextAffinity = {Downstream, Upstream}. Upstream means beforeLineWrap.

When I work on LTR in RTL case, I found TextAffinity helps explaining caret position.

For example: <div dir=rtl style="padding: 50px">abcdef</div>

When clicking left edge, each browser sets selection as caret to:

All UAs display caret before a, like |abcdef, where | denotes caret. Note: This is as same as collapse("abcdef", 0) except for Chrome.

When typing "X", after clicking left edge:

If we have TextAffinity, Chrome can use abcdefX@7/Upstream, to place caret after X, e.g. abcdefX|, and left edge clicking as abcdef@0/Downstream as Edge/Firefox.

For collapse("abcdef", 0), collapse("abcdef", 6)

Other examples found in https://goo.gl/A5yhvl

rniwa commented 7 years ago

We definitely don't want to expose downstream/upstream. They're contrived concepts.

rniwa commented 5 years ago

One thing we have to keep in mind is that different browser engine assigns different offsets at bidi-level boundary. So depending on what the use cases are, we may need to specify where the visual location would be vs. between which logical characters the caret will be placed.

marijnh commented 4 years ago

I strongly support this.

Firefox has exposed Selection.caretBidiLevel for a while, which helps a lot with this, in that it allows scripts to figure out where a caret actually is, and create a selection at precisely that position. I was not able to find any effort to standardize this, but having it portably available would be extremely valuable.

What would be the steps required to get discussion going on this? Opening an issue doesn't seem to have done a lot, judging by this one's progress.