X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftext.C;h=8e68a70a32f797702cf157a8266ab2fa36d220dd;hb=fe390e9da1538e20eabbc98977d845295f8e563d;hp=4396e1989459bf91eaa2ddc0f26d4b09b5df8591;hpb=fa78e1ddb6d0835cbde7b94bf97753122336117d;p=lyx.git diff --git a/src/text.C b/src/text.C index 4396e19894..8e68a70a32 100644 --- a/src/text.C +++ b/src/text.C @@ -30,6 +30,7 @@ #include "language.h" #include "ParagraphParameters.h" #include "undo_funcs.h" +#include "text_funcs.h" #include "WordLangTuple.h" #include "paragraph_funcs.h" #include "rowpainter.h" @@ -43,11 +44,16 @@ #include +using namespace lyx::support; + using std::max; using std::min; using std::endl; using std::pair; + using lyx::pos_type; +using lyx::word_location; + using namespace bv_funcs; /// top, right, bottom pixel margin @@ -62,14 +68,14 @@ extern int bibitemMaxWidth(BufferView *, LyXFont const &); BufferView * LyXText::bv() { - lyx::Assert(bv_owner != 0); + Assert(bv_owner != 0); return bv_owner; } BufferView * LyXText::bv() const { - lyx::Assert(bv_owner != 0); + Assert(bv_owner != 0); return bv_owner; } @@ -150,10 +156,10 @@ int LyXText::workWidth(Inset const * inset) const ParagraphList::iterator par = std::find(ownerParagraphs().begin(), ownerParagraphs().end(), *inset->parOwner()); - //lyx::Assert(par); + //Assert(par); pos_type pos = par->getPositionOfInset(inset); - lyx::Assert(pos != -1); + Assert(pos != -1); LyXLayout_ptr const & layout = par->layout(); @@ -971,7 +977,7 @@ int LyXText::labelFill(Row const & row) const pos_type last = pit->beginningOfBody(); - lyx::Assert(last > 0); + Assert(last > 0); // -1 because a label ends either with a space that is in the label, // or with the beginning of a footnote that is outside the label. @@ -1011,7 +1017,7 @@ LColor::color LyXText::backgroundColor() const void LyXText::setHeightOfRow(RowList::iterator rit) { - lyx::Assert(rit != rows().end()); + Assert(rit != rows().end()); // get the maximum ascent and the maximum descent float layoutasc = 0; @@ -1323,7 +1329,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) // start at the implicit given position void LyXText::appendParagraph(RowList::iterator rowit) { - lyx::Assert(rowit != rowlist_.end()); + Assert(rowit != rowlist_.end()); pos_type const last = rowit->par()->size(); bool done = false; @@ -1353,7 +1359,7 @@ void LyXText::appendParagraph(RowList::iterator rowit) void LyXText::breakAgain(RowList::iterator rit) { - lyx::Assert(rit != rows().end()); + Assert(rit != rows().end()); bool not_ready = true; @@ -1406,7 +1412,7 @@ void LyXText::breakAgain(RowList::iterator rit) // this is just a little changed version of break again void LyXText::breakAgainOneRow(RowList::iterator rit) { - lyx::Assert(rit != rows().end()); + Assert(rit != rows().end()); pos_type z = rowBreakPoint(*rit); RowList::iterator tmprit = rit; @@ -1974,27 +1980,8 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x, void LyXText::cursorRightOneWord() { - // treat floats, HFills and Insets as words - ParagraphList::iterator pit = cursor.par(); - pos_type pos = cursor.pos(); - - // CHECK See comment on top of text.C - - if (pos == pit->size() - && boost::next(pit) != ownerParagraphs().end()) { - ++pit; - pos = 0; - } else { - // Skip through initial nonword stuff. - while (pos < pit->size() && !pit->isWord(pos)) { - ++pos; - } - // Advance through word. - while (pos < pit->size() && pit->isWord(pos)) { - ++pos; - } - } - setCursor(pit, pos); + ::cursorRightOneWord(cursor, ownerParagraphs()); + setCursor(cursor.par(), cursor.pos()); } @@ -2003,102 +1990,16 @@ void LyXText::cursorRightOneWord() void LyXText::cursorLeftOneWord() { LyXCursor tmpcursor = cursor; - cursorLeftOneWord(tmpcursor); + ::cursorLeftOneWord(tmpcursor, ownerParagraphs()); setCursor(tmpcursor.par(), tmpcursor.pos()); } -void LyXText::cursorLeftOneWord(LyXCursor & cur) -{ - // treat HFills, floats and Insets as words - - ParagraphList::iterator pit = cursor.par(); - pos_type pos = cursor.pos(); - - while (pos && - (pit->isSeparator(pos - 1) || - pit->isKomma(pos - 1) || - pit->isNewline(pos - 1)) && - !(pit->isHfill(pos - 1) || - pit->isInset(pos - 1))) - --pos; - - if (pos && - (pit->isInset(pos - 1) || - pit->isHfill(pos - 1))) { - --pos; - } else if (!pos) { - if (pit != ownerParagraphs().begin()) { - --pit; - pos = pit->size(); - } - } else { // Here, cur != 0 - while (pos > 0 && - pit->isWord(pos - 1)) - --pos; - } - - cur.par(pit); - cur.pos(pos); -} - - -// 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) -{ - // 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); - } -} - - void LyXText::selectWord(word_location loc) { - LyXCursor from; + LyXCursor from = cursor; LyXCursor to; - getWord(from, to, loc); + ::getWord(from, to, loc, ownerParagraphs()); if (cursor != from) setCursor(from.par(), from.pos()); if (to == from) @@ -2356,7 +2257,8 @@ void LyXText::changeCase(LyXText::TextCase action) from = selection.start; to = selection.end; } else { - getWord(from, to, PARTIAL_WORD); + from = cursor; + ::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs()); setCursor(to.par(), to.pos() + 1); }