Skip to content

Maintain selection and composition during updateText() #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from

Conversation

dandclark
Copy link
Contributor

@dandclark dandclark commented Mar 13, 2025

Make the following changes to keep the selection and composition in a consistent state after updateText()/updateSelection() calls.

  • For each selection boundary point, updateText() sets the boundary point to boundaryPoint + text.length - (rangeEnd - rangeStart) when boundaryPoint >= rangeEnd, or to rangeStart + text.length when boundaryPoint > rangeStart && boundaryPoint < rangeEnd.
  • When a composition is active during an updateText() call,
    • If the updated range does not overlap with the composed range, move the composition position in the same way as for selection.
    • If it does overlap, abort the composition.
  • When a composition is active when updateSelection() is called with a selection that differs from the current selection, abort the composition.

Resolves #111.

For normative changes, the following tasks have been completed:

@marijnh
Copy link

marijnh commented Mar 13, 2025

Thanks. These changes would solve the issues I've been running into.

aarongable pushed a commit to chromium/chromium that referenced this pull request May 20, 2025
This CL adds use counters to analyze the impact of implementing the
change proposed in [1]. Following counters are added:
1. kEditContextUpdateTextRangePrecedesOrOverlapsSelection: Tracks when
updateText is called and the update range precedes or overlaps the
selection.
2. kEditContextUpdateTextRangePrecedesCompositionRange: Tracks when
updateText is called and the update range precedes the composition
range during an active composition.
3. kEditContextUpdateTextRangeOverlapsCompositionRange: Tracks when
updateText is called and the update range overlaps with the composition
range during an active composition.
4. kEditContextUpdateSelectionDuringActiveComposition: Tracks when
updateSelection is called during an active composition.

[1] w3c/edit-context#115

These counters will help us understand how frequently these behaviors
occur before making changes to the spec implementation.

Bug: 379170477
Change-Id: I8043fdb6161137f79d8eaa3336b90d93ca25042c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6549358
Reviewed-by: Dan Clark <[email protected]>
Commit-Queue: Ashish Kumar <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1462602}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The interaction between composition and updateText/updateSelection should be more clearly defined
2 participants