#6112·slate

A collapsed range ought to be considered neither forward nor backward

Author: nabbydudeCreated Sep 20, 2026Updated Sep 20, 2026
Labelsimprovement

Problem Currently Range.isForward returns true for collapsed ranges. This is because it's defined as the opposite of Range.isBackward, which in turn calls Point.isAfter(focus, anchor). This seems more like an implementation quirk than intentional design.

Solution It seems logical to me that a collapsed range returns false for both Range.isForward and Range.isBackward. Since it would return true for Range.isCollapsed these three functions would be a mutually-exclusive triple, corresponding to Point.isBefore, Point.isAfter, and Point.equals, or the 3 possible results of Point.compare/Path.compare

This is unlikely to break existing code--and if it does, only minorly--since it's often structured like so:

typescript
if (Range.isForward(range)) {
  // do X
} else {
  // do Y, which on a collapsed range is inconsequentially different than X, if not exactly equivalent
}

Alternatives We could leave the behavior as-is and just document it but I think the above change makes for a cleaner API