- if (old.pos() == 0 && old.pit() != 0) {
- --old.pit();
- old.pos() = old.lastpos();
- } else {
- // Skip through initial nonword stuff.
- while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
- --old.pos();
- // Advance through word.
- while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
- --old.pos();
+ // Skip through puctuation and spaces.
+ while (pos != 0 && par.isChar(pos - 1))
+ --pos;
+
+ // Skip over either a non-char inset or a full word
+ if (pos != 0 && !par.isLetter(pos) && !par.isChar(pos - 1))
+ --pos;
+ else while (pos != 0 && par.isLetter(pos - 1))
+ --pos;
+
+ if (pos == 0 && pit != 0) {
+ --pit;
+ pos = getPar(cur.pit() - 1).size();
+ }
+
+ return setCursor(cur, pit, pos);
+}
+
+
+bool Text::cursorVisLeftOneWord(Cursor & cur)
+{
+ LASSERT(this == cur.text(), /**/);
+
+ pos_type left_pos, right_pos;
+ bool left_is_letter, right_is_letter;
+
+ Cursor temp_cur = cur;
+
+ // always try to move at least once...
+ while (temp_cur.posVisLeft(true /* skip_inset */)) {
+
+ // collect some information about current cursor position
+ temp_cur.getSurroundingPos(left_pos, right_pos);
+ left_is_letter =
+ (left_pos > -1 ? temp_cur.paragraph().isLetter(left_pos) : false);
+ right_is_letter =
+ (right_pos > -1 ? temp_cur.paragraph().isLetter(right_pos) : false);
+
+ // if we're not at a letter/non-letter boundary, continue moving
+ if (left_is_letter == right_is_letter)
+ continue;
+
+ // we should stop when we have an LTR word on our right or an RTL word
+ // on our left
+ if ((left_is_letter && temp_cur.paragraph().getFontSettings(
+ temp_cur.bv().buffer().params(),
+ left_pos).isRightToLeft())
+ || (right_is_letter && !temp_cur.paragraph().getFontSettings(
+ temp_cur.bv().buffer().params(),
+ right_pos).isRightToLeft()))
+ break;