mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
9.22k stars 22.5k forks source link

updateSelection: make more intuitive #36834

Closed mikecat closed 4 days ago

mikecat commented 4 days ago

Description

Making when to throw exceptions more intuitive.

Motivation

Additional details

With my experiment with Google Chrome 131.0.6778.70, following things didn't throw exceptions:

What to do with negative start and end doesn't seem defined and I thought that there may be an environment where exceptions are thrown in such cases.

However, the other cases seems quite natural and I don't think exceptions should be thrown in such cases.

Quote from the definitions of EditContext state in EditContext API:

  • selection start which refers to the offset in text where the selection starts. The initial value is 0.
  • selection end which refers to the offset in text where the selection ends. The initial value is 0. selection end may be less than selection start in the case of a "backwards" selection (in reverse of document order).

The "selection start" and "selection end" are what are set based on start and end passed to updateSelection() in the EditContext Interface.

Related issues and pull requests

github-actions[bot] commented 4 days ago

Preview URLs