icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Add DoubleEndedIterator support to icu_segmenter iterators

Open White-Green opened this issue 3 months ago • 2 comments

Feature Request

I would like to propose adding DoubleEndedIterator support to the iterators in icu_segmenter, in particular GraphemeClusterBreakIterator.

Motivation / Use Case

My primary use case is implementing text editor behavior.
For example, when handling the Left Arrow key or Backspace, the editor needs to move the cursor or delete the previous grapheme cluster.
Currently, icu_segmenter only supports forward iteration, which means I have to collect all break positions first and then traverse them in reverse. This is less efficient and less ergonomic.

Scope

Although my immediate need is for GraphemeClusterBreakIterator, the implementation would naturally extend to other iterators as well.
This is because GraphemeClusterBreakIterator and the other break iterators (word, sentence, line) are all built on top of the common RuleBreakIterator.
If RuleBreakIterator itself implements DoubleEndedIterator, then all higher-level iterators will automatically gain reverse-iteration capability.

I would appreciate it if the maintainers could consider this feature request.

White-Green avatar Sep 28 '25 01:09 White-Green

CC @makotokato @aethanyc

sffc avatar Sep 29 '25 21:09 sffc

Yup, supporting reverse iteration in break iterators would be useful. Firefox has a similar bug that depends on this capability in GraphemeClusterBreakIterator (see bug 1847807).

aethanyc avatar Sep 30 '25 00:09 aethanyc