-void LyXText::cursorLeftOneWord(LyXCursor & cur) const
-{
- // treat HFills, floats and Insets as words
- cur = cursor;
- while (cur.pos()
- && (cur.par()->isSeparator(cur.pos() - 1)
- || cur.par()->isKomma(cur.pos() - 1)
- || cur.par()->isNewline(cur.pos() - 1))
- && !(cur.par()->isHfill(cur.pos() - 1)
- || cur.par()->isInset(cur.pos() - 1)))
- cur.pos(cur.pos() - 1);
-
- if (cur.pos()
- && (cur.par()->isInset(cur.pos() - 1)
- || cur.par()->isHfill(cur.pos() - 1))) {
- cur.pos(cur.pos() - 1);
- } else if (!cur.pos()) {
- if (cur.par()->previous()) {
- cur.par(cur.par()->previous());
- cur.pos(cur.par()->size());
- }
- } else { // Here, cur != 0
- while (cur.pos() > 0 &&
- cur.par()->isWord(cur.pos() - 1))
- cur.pos(cur.pos() - 1);
- }
-}
-
-
-// Select current word. This depends on behaviour of
-// CursorLeftOneWord(), so it is patched as well.
-void LyXText::getWord(LyXCursor & from, LyXCursor & to,
- word_location const loc) const
-{
- // first put the cursor where we wana start to select the word
- from = cursor;
- switch (loc) {
- case WHOLE_WORD_STRICT:
- if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
- || cursor.par()->isSeparator(cursor.pos())
- || cursor.par()->isKomma(cursor.pos())
- || cursor.par()->isNewline(cursor.pos())
- || cursor.par()->isSeparator(cursor.pos() - 1)
- || cursor.par()->isKomma(cursor.pos() - 1)
- || cursor.par()->isNewline(cursor.pos() - 1)) {
- to = from;
- return;
- }
- // no break here, we go to the next
-
- case WHOLE_WORD:
- // Move cursor to the beginning, when not already there.
- if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
- && !(from.par()->isKomma(from.pos() - 1)
- || from.par()->isNewline(from.pos() - 1)))
- cursorLeftOneWord(from);
- break;
- case PREVIOUS_WORD:
- // always move the cursor to the beginning of previous word
- cursorLeftOneWord(from);
- break;
- case NEXT_WORD:
- lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
- break;
- case PARTIAL_WORD:
- break;
- }
- to = from;
- while (to.pos() < to.par()->size()
- && !to.par()->isSeparator(to.pos())
- && !to.par()->isKomma(to.pos())
- && !to.par()->isNewline(to.pos())
- && !to.par()->isHfill(to.pos())
- && !to.par()->isInset(to.pos()))
- {
- to.pos(to.pos() + 1);
- }
-}
-
-