GoogleChromeLabs / text-fragments-polyfill

Apache License 2.0
116 stars 27 forks source link

Fix extraneous characters when expanding JP ranges #97

Closed tfmar closed 3 years ago

tfmar commented 3 years ago

Currently when we call expandToNearestWordBoundaryPointUsingSegments on text in Japanese (or any non-space-separated language) we often include too much text. This is because, if the range already ends on a word boundary, we jump to the end of the segment where it ends (i.e., we add another word).

The fix for this is simple; we just early-return whenever the range points to the beginning/end of a segment, regardless of whether or not that segment is whitespace.