Skip to content

updateSelection: make more intuitive#36834

Merged
sideshowbarker merged 1 commit intomdn:mainfrom
mikecat:updateselection-make-more-intuitive
Nov 18, 2024
Merged

updateSelection: make more intuitive#36834
sideshowbarker merged 1 commit intomdn:mainfrom
mikecat:updateselection-make-more-intuitive

Conversation

@mikecat
Copy link
Copy Markdown
Contributor

@mikecat mikecat commented Nov 17, 2024

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:

  • Making start greater than end: editContext.updateSelection(10, 5);
  • Making start and end zero: editContext.updateSelection(0, 0);
  • Making start and end negative: editContext.updateSelection(-1, -2);
    • This resulted in having both of start and end at the end of text.

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.

  • Zero is used to represent the head of the string. It is quite natural to select from there or to move the caret there.
  • Having the end of the selection before the start of the selection is explicitly allowed. Therefore, there doesn't seem reasons that prevent this method from setting such selections.

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

@mikecat mikecat requested a review from a team as a code owner November 17, 2024 23:36
@mikecat mikecat requested review from sideshowbarker and removed request for a team November 17, 2024 23:36
@github-actions github-actions bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Nov 17, 2024
@github-actions
Copy link
Copy Markdown
Contributor

@sideshowbarker sideshowbarker merged commit ab5aa44 into mdn:main Nov 18, 2024
@mikecat mikecat deleted the updateselection-make-more-intuitive branch November 18, 2024 00:22
wbamberg added a commit to wbamberg/content that referenced this pull request Nov 27, 2024
* origin/xss-guide: (284 commits)
  Add information on default entryPoint property values (mdn#36633)
  Bump husky from 9.1.6 to 9.1.7 (mdn#36863)
  fix(performance): Typo '50ms seconds' (mdn#36861)
  Add spec_url & add note for bcd for `<frequency>` and `<frequency-percentage>` (mdn#36848)
  addresses 36583: summary icon styles (mdn#36691)
  Remove "simple" part 3: change to "basic"  (mdn#36762)
  the default option of a select (mdn#36658)
  docs(css): Add support for `<string>` in `syntax` descriptor of @Property at-rule (mdn#36655)
  Fix parameter syntax for `Navigation.updateCurrentEntry()` (mdn#36852)
  Update CSP source expression reference (mdn#36792)
  chore(http): Refresh headers docs (d-k) (mdn#36075)
  chore(http): Refresh headers r-s (mdn#36590)
  Updated index.md (mdn#36845)
  fix : wrong method name (mdn#36843)
  Remove all redirects to other locales (mdn#36811)
  fix typos (mdn#36837)
  docs: update Accept-Charset status (mdn#36822)
  updateSelection: make more intuitive (mdn#36834)
  updateText: Remove false information (mdn#36832)
  DOMRect instance properties (mdn#36704)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants