X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FText.cpp;h=187e3872312f2ff66f3edb5705906c85703f5cfe;hb=f1a388584fb2c043d17127d7db49c36cb8427cfa;hp=1eecee1e30443e9b068a24538508a361de7fac97;hpb=11ca1406671f3e7b126bbe9b51694e8d32ba161c;p=lyx.git diff --git a/src/Text.cpp b/src/Text.cpp index 1eecee1e30..187e387231 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -66,11 +66,9 @@ #include "support/gettext.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" #include "support/textutils.h" -#include - -#include #include @@ -137,7 +135,7 @@ void breakParagraphConservative(BufferParams const & bparams, ParagraphList & pars, pit_type par_offset, pos_type pos) { // create a new paragraph - Paragraph & tmp = *pars.insert(boost::next(pars.begin(), par_offset + 1), + Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), par_offset + 1), Paragraph()); Paragraph & par = pars[par_offset]; @@ -193,7 +191,7 @@ void mergeParagraph(BufferParams const & bparams, // move the change of the end-of-paragraph character par.setChange(par.size(), change); - pars.erase(boost::next(pars.begin(), par_offset + 1)); + pars.erase(lyx::next(pars.begin(), par_offset + 1)); } @@ -362,7 +360,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex, string const & token, Font & font, Change & change, ErrorList & errorList) { Buffer * buf = const_cast(&owner_->buffer()); - BufferParams const & bp = buf->params(); + BufferParams & bp = buf->params(); if (token[0] != '\\') { docstring dstr = lex.getDocString(); @@ -536,18 +534,25 @@ void Text::readParToken(Paragraph & par, Lexer & lex, int aid; time_t ct; is >> aid >> ct; - BufferParams::AuthorMap const & am = bp.author_map; + BufferParams::AuthorMap const & am = bp.author_map_; if (am.find(aid) == am.end()) { - errorList.push_back(ErrorItem(_("Change tracking error"), - bformat(_("Unknown author index for change: %1$d\n"), aid), - par.id(), 0, par.size())); - change = Change(Change::UNCHANGED); - } else { - if (token == "\\change_inserted") - change = Change(Change::INSERTED, am.find(aid)->second, ct); - else - change = Change(Change::DELETED, am.find(aid)->second, ct); + errorList.push_back(ErrorItem( + _("Change tracking author index missing"), + bformat(_("A change tracking author information for index " + "%1$d is missing. This can happen after a wrong " + "merge by a version control system. In this case, " + "either fix the merge, or have this information " + "missing until the corresponding tracked changes " + "are merged or this user edits the file again.\n"), + aid), + par.id(), par.size(), par.size() + 1 + )); + bp.addAuthor(Author(aid)); } + if (token == "\\change_inserted") + change = Change(Change::INSERTED, am.find(aid)->second, ct); + else + change = Change(Change::DELETED, am.find(aid)->second, ct); } else { lex.eatLine(); errorList.push_back(ErrorItem(_("Unknown token"), @@ -663,7 +668,7 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos, ParagraphList & pars = text.paragraphs(); // create a new paragraph, and insert into the list ParagraphList::iterator tmp = - pars.insert(boost::next(pars.begin(), par_offset + 1), + pars.insert(lyx::next(pars.begin(), par_offset + 1), Paragraph()); Paragraph & par = pars[par_offset]; @@ -848,7 +853,7 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str, } else { continue; } - // do not insert consecutive spaces if !free_spacing + // do not insert consecutive spaces if !free_spacing } else if ((*cit == ' ' || *cit == '\t') && space_inserted && !par.isFreeSpacing()) { continue; @@ -1115,7 +1120,7 @@ bool Text::cursorForwardOneWord(Cursor & cur) if (lyxrc.mac_like_cursor_movement) { // Skip through trailing punctuation and spaces. while (pos != lastpos && (par.isChar(pos) || par.isSpace(pos))) - ++pos; + ++pos; // Skip over either a non-char inset or a full word if (pos != lastpos && par.isWordSeparator(pos)) @@ -1188,7 +1193,6 @@ bool Text::cursorVisLeftOneWord(Cursor & cur) LBUFERR(this == cur.text()); pos_type left_pos, right_pos; - bool left_is_letter, right_is_letter; Cursor temp_cur = cur; @@ -1197,9 +1201,9 @@ bool Text::cursorVisLeftOneWord(Cursor & cur) // collect some information about current cursor position temp_cur.getSurroundingPos(left_pos, right_pos); - left_is_letter = + bool left_is_letter = (left_pos > -1 ? !temp_cur.paragraph().isWordSeparator(left_pos) : false); - right_is_letter = + bool right_is_letter = (right_pos > -1 ? !temp_cur.paragraph().isWordSeparator(right_pos) : false); // if we're not at a letter/non-letter boundary, continue moving @@ -1225,7 +1229,6 @@ bool Text::cursorVisRightOneWord(Cursor & cur) LBUFERR(this == cur.text()); pos_type left_pos, right_pos; - bool left_is_letter, right_is_letter; Cursor temp_cur = cur; @@ -1234,9 +1237,9 @@ bool Text::cursorVisRightOneWord(Cursor & cur) // collect some information about current cursor position temp_cur.getSurroundingPos(left_pos, right_pos); - left_is_letter = + bool left_is_letter = (left_pos > -1 ? !temp_cur.paragraph().isWordSeparator(left_pos) : false); - right_is_letter = + bool right_is_letter = (right_pos > -1 ? !temp_cur.paragraph().isWordSeparator(right_pos) : false); // if we're not at a letter/non-letter boundary, continue moving @@ -1263,7 +1266,7 @@ void Text::selectWord(Cursor & cur, word_location loc) { LBUFERR(this == cur.text()); CursorSlice from = cur.top(); - CursorSlice to = cur.top(); + CursorSlice to; getWord(from, to, loc); if (cur.top() != from) setCursor(cur, from.pit(), from.pos()); @@ -1491,20 +1494,19 @@ void Text::deleteWordBackward(Cursor & cur) // Kill to end of line. -void Text::changeCase(Cursor & cur, TextCase action) +void Text::changeCase(Cursor & cur, TextCase action, bool partial) { LBUFERR(this == cur.text()); CursorSlice from; CursorSlice to; - bool gotsel = false; - if (cur.selection()) { + bool const gotsel = cur.selection(); + if (gotsel) { from = cur.selBegin(); to = cur.selEnd(); - gotsel = true; } else { from = cur.top(); - getWord(from, to, PARTIAL_WORD); + getWord(from, to, partial ? PARTIAL_WORD : WHOLE_WORD); cursorForwardOneWord(cur); } @@ -1641,14 +1643,14 @@ bool Text::backspacePos0(Cursor & cur) if (cur.lastpos() == 0 || (cur.lastpos() == 1 && par.isSeparator(0))) { cur.recordUndo(prevcur.pit()); - plist.erase(boost::next(plist.begin(), cur.pit())); + plist.erase(lyx::next(plist.begin(), cur.pit())); needsUpdate = true; } // is previous par empty? else if (prevcur.lastpos() == 0 || (prevcur.lastpos() == 1 && prevpar.isSeparator(0))) { cur.recordUndo(prevcur.pit()); - plist.erase(boost::next(plist.begin(), prevcur.pit())); + plist.erase(lyx::next(plist.begin(), prevcur.pit())); needsUpdate = true; } // Pasting is not allowed, if the paragraphs have different @@ -2048,16 +2050,25 @@ docstring Text::asString(pit_type beg, pit_type end, int options) const } -void Text::forOutliner(docstring & os, size_t maxlen, bool shorten) const +void Text::shortenForOutliner(docstring & str, size_t const maxlen) { - if (maxlen == 0) - maxlen = std::numeric_limits::max(); - else - LASSERT(maxlen >= 8, maxlen = TOC_ENTRY_LENGTH); - for (size_t i = 0; i != pars_.size() && os.length() < maxlen; ++i) - pars_[i].forOutliner(os, maxlen); - if (shorten && os.length() >= maxlen) - os = os.substr(0, maxlen - 3) + from_ascii("..."); + support::truncateWithEllipsis(str, maxlen); + docstring::iterator it = str.begin(); + docstring::iterator end = str.end(); + for (; it != end; ++it) + if ((*it) == L'\n' || (*it) == L'\t') + (*it) = L' '; +} + + +void Text::forOutliner(docstring & os, size_t const maxlen, + bool const shorten) const +{ + size_t tmplen = shorten ? maxlen + 1 : maxlen; + for (size_t i = 0; i != pars_.size() && os.length() < tmplen; ++i) + pars_[i].forOutliner(os, tmplen, false); + if (shorten) + shortenForOutliner(os, maxlen); }