Skip to content

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

Open

Description

@rniwa

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.

Activity

  1. yosinch commented on Apr 13, 2017

    @yosinch

    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:

    • Chrome: abcdef@6 |abcdef
    • Edge: abcdef@0 |abcdef
    • Firefox: abcdef@0 |abcdef

    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:

    • Chrome: abcdefX@7 |abcdefX
    • Edge: Xabcdef@1 X|abcdef
    • Firefox: Xabcdef@1 X|abcdef

    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)

    • Chrome abcdef| |abcdef
    • Edge: |abcdef abcdef|
    • Firefox: |abcdef abcdef|

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

  2. rniwa commented on Apr 13, 2017

    @rniwa
    ContributorAuthor

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

  3. rniwa commented on Mar 23, 2019

    @rniwa
    ContributorAuthor

    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.

  4. marijnh commented on Jan 23, 2020

    @marijnh

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions