Skip to content

TextSelection doesn't support TextAffinities for non-collapsed selection #88135

@justinmc

Description

@justinmc

TextSelection has a single affinity property, and according to its docs, it only applies when collapsed:

If the text range is collapsed and has more than one visual location (e.g., occurs at a line break), which of the two locations to use when painting the caret.

I think that this may be an oversight and a source of bugs, especially when using a keyboard. For example, these selections are different, but Flutter has no way to distinguish between the two:

extent TextAffinity.downstream extent TextAffinity.upstream Flutter treats them both as:
This text wra|ps because it's
|too long.
This text wra|ps because it's |
too long.
Screen Shot 2021-08-12 at 6 32 07 PM

Why does it matter?

When using keyboard shortcuts that jump to the beginning/end of a line, it's important to know what line the base and extent are on. Consider doing cmd-shift-right (expand to end of line) in my example in the table above. If the extent is upstream, the selection shouldn't change. If it's downstream, it should select to the end fo the field. Always assuming one or the other affinity won't always make sense.

Related

https://github.com/flutter/flutter/pull/87973/files#r685632915
#85653

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions