- // if the position *after* left_pos is not RTL, set boundary to
- // true (we want to be *after* left_pos, not before left_pos + 1!)
- new_boundary = !cur.paragraph().getFontSettings(
- cur.bv().buffer().params(), new_pos).isVisibleRightToLeft();
+ // set the boundary to true in two situations:
+ if (
+ // 1. if new_pos is now lastpos (which means that we're moving left
+ // to the end of an RTL chunk which is at the end of an LTR
+ // paragraph);
+ new_pos == cur.lastpos()
+ // 2. if the position *after* left_pos is not RTL (we want to be
+ // *after* left_pos, not before left_pos + 1!)
+ || !cur.paragraph().getFontSettings(cur.bv().buffer().params(),
+ new_pos).isVisibleRightToLeft()
+ )
+ new_boundary = true;
+ else // set the boundary to false
+ new_boundary = false;