X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FText.cpp;h=a2ae1aed8f33b772ea527dbb824c2ff9b874bc4f;hb=0a93c9b70f861b12e27239167d9ba59ddd6ece1e;hp=70805dfe8408b4c465bb1ffe054805eac85a022d;hpb=5aede9597124b1a67abfd40521bc4984074ea413;p=lyx.git diff --git a/src/Text.cpp b/src/Text.cpp index 70805dfe84..a2ae1aed8f 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -30,6 +30,7 @@ #include "Cursor.h" #include "CutAndPaste.h" #include "DispatchResult.h" +#include "Encoding.h" #include "ErrorList.h" #include "FuncRequest.h" #include "factory.h" @@ -156,7 +157,7 @@ void breakParagraphConservative(BufferParams const & bparams, } // Move over the end-of-par change information tmp.setChange(tmp.size(), par.lookupChange(par.size())); - par.setChange(par.size(), Change(bparams.trackChanges ? + par.setChange(par.size(), Change(bparams.track_changes ? Change::INSERTED : Change::UNCHANGED)); } } @@ -690,7 +691,7 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos, // Move over the end-of-par change information tmp->setChange(tmp->size(), par.lookupChange(par.size())); - par.setChange(par.size(), Change(bparams.trackChanges ? + par.setChange(par.size(), Change(bparams.track_changes ? Change::INSERTED : Change::UNCHANGED)); if (pos) { @@ -748,7 +749,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic) // Always break behind a space // It is better to erase the space (Dekel) if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos())) - cpar.eraseChar(cur.pos(), cur.buffer()->params().trackChanges); + cpar.eraseChar(cur.pos(), cur.buffer()->params().track_changes); // What should the layout for the new paragraph be? bool keep_layout = layout.isEnvironment() @@ -783,7 +784,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic) } while (!pars_[next_par].empty() && pars_[next_par].isNewline(0)) { - if (!pars_[next_par].eraseChar(0, cur.buffer()->params().trackChanges)) + if (!pars_[next_par].eraseChar(0, cur.buffer()->params().track_changes)) break; // the character couldn't be deleted physically due to change tracking } @@ -830,11 +831,11 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str, } else if (*cit == '\t') { if (!par.isFreeSpacing()) { // tabs are like spaces here - par.insertChar(pos, ' ', font, bparams.trackChanges); + par.insertChar(pos, ' ', font, bparams.track_changes); ++pos; space_inserted = true; } else { - par.insertChar(pos, *cit, font, bparams.trackChanges); + par.insertChar(pos, *cit, font, bparams.track_changes); ++pos; space_inserted = true; } @@ -843,7 +844,7 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str, continue; } else { // just insert the character - par.insertChar(pos, *cit, font, bparams.trackChanges); + par.insertChar(pos, *cit, font, bparams.track_changes); ++pos; space_inserted = (*cit == ' '); } @@ -920,6 +921,7 @@ void Text::insertChar(Cursor & cur, char_type c) if (contains(number_unary_operators, c) && (cur.pos() == 1 || par.isSeparator(cur.pos() - 2) + || par.isEnvSeparator(cur.pos() - 2) || par.isNewline(cur.pos() - 2)) ) { setCharFont(pit, cur.pos() - 1, cur.current_font, @@ -1004,8 +1006,21 @@ void Text::insertChar(Cursor & cur, char_type c) } } + // Prevent to insert uncodable characters in verbatim and ERT + // (workaround for bug 9012) + // Don't do it for listings inset, since InsetListings::latex() tries + // to switch to a usable encoding which works in many cases (bug 9102). + if (cur.paragraph().isPassThru() && owner_->lyxCode() != LISTINGS_CODE && + cur.current_font.language()) { + Encoding const * e = cur.current_font.language()->encoding(); + if (!e->encodable(c)) { + cur.message(_("Character is uncodable in verbatim paragraphs.")); + return; + } + } + par.insertChar(cur.pos(), c, cur.current_font, - cur.buffer()->params().trackChanges); + cur.buffer()->params().track_changes); cur.checkBufferStructure(); // cur.screenUpdateFlags(Update::Force); @@ -1261,8 +1276,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) LBUFERR(this == cur.text()); if (!cur.selection()) { - bool const changed = cur.paragraph().isChanged(cur.pos()); - if (!(changed && findNextChange(&cur.bv()))) + if (!selectChange(cur)) return; } @@ -1278,7 +1292,6 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) bool endsBeforeEndOfPar = (endPos < pars_[endPit].size()); // first, accept/reject changes within each individual paragraph (do not consider end-of-par) - for (pit_type pit = begPit; pit <= endPit; ++pit) { pos_type parSize = pars_[pit].size(); @@ -1354,10 +1367,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) } // finally, invoke the DEPM - - deleteEmptyParagraphMechanism(begPit, endPit, cur.buffer()->params().trackChanges); - - // + deleteEmptyParagraphMechanism(begPit, endPit, cur.buffer()->params().track_changes); cur.finishUndo(); cur.clearSelection(); @@ -1371,7 +1381,7 @@ void Text::acceptChanges() { BufferParams const & bparams = owner_->buffer().params(); lyx::acceptChanges(pars_, bparams); - deleteEmptyParagraphMechanism(0, pars_.size() - 1, bparams.trackChanges); + deleteEmptyParagraphMechanism(0, pars_.size() - 1, bparams.track_changes); } @@ -1407,7 +1417,7 @@ void Text::rejectChanges() } // finally, invoke the DEPM - deleteEmptyParagraphMechanism(0, pars_size - 1, bparams.trackChanges); + deleteEmptyParagraphMechanism(0, pars_size - 1, bparams.track_changes); } @@ -1537,7 +1547,7 @@ bool Text::erase(Cursor & cur) // any paragraphs cur.recordUndo(DELETE_UNDO); bool const was_inset = cur.paragraph().isInset(cur.pos()); - if(!par.eraseChar(cur.pos(), cur.buffer()->params().trackChanges)) + if(!par.eraseChar(cur.pos(), cur.buffer()->params().track_changes)) // the character has been logically deleted only => skip it cur.top().forwardPos(); @@ -1550,7 +1560,7 @@ bool Text::erase(Cursor & cur) if (cur.pit() == cur.lastpit()) return dissolveInset(cur); - if (!par.isMergedOnEndOfParDeletion(cur.buffer()->params().trackChanges)) { + if (!par.isMergedOnEndOfParDeletion(cur.buffer()->params().track_changes)) { par.setChange(cur.pos(), Change(Change::DELETED)); cur.forwardPos(); needsUpdate = true; @@ -1637,7 +1647,7 @@ bool Text::backspace(Cursor & cur) Cursor prev_cur = cur; --prev_cur.pit(); - if (!prev_cur.paragraph().isMergedOnEndOfParDeletion(cur.buffer()->params().trackChanges)) { + if (!prev_cur.paragraph().isMergedOnEndOfParDeletion(cur.buffer()->params().track_changes)) { cur.recordUndo(ATOMIC_UNDO, prev_cur.pit(), prev_cur.pit()); prev_cur.paragraph().setChange(prev_cur.lastpos(), Change(Change::DELETED)); setCursorIntern(cur, prev_cur.pit(), prev_cur.lastpos()); @@ -1658,7 +1668,7 @@ bool Text::backspace(Cursor & cur) setCursorIntern(cur, cur.pit(), cur.pos() - 1, false, cur.boundary()); bool const was_inset = cur.paragraph().isInset(cur.pos()); - cur.paragraph().eraseChar(cur.pos(), cur.buffer()->params().trackChanges); + cur.paragraph().eraseChar(cur.pos(), cur.buffer()->params().track_changes); if (was_inset) cur.forceBufferUpdate(); else @@ -1700,7 +1710,7 @@ bool Text::dissolveInset(Cursor & cur) spos += cur.pos(); spit += cur.pit(); Buffer & b = *cur.buffer(); - cur.paragraph().eraseChar(cur.pos(), b.params().trackChanges); + cur.paragraph().eraseChar(cur.pos(), b.params().track_changes); if (!plist.empty()) { // see bug 7319 @@ -1835,7 +1845,7 @@ docstring Text::currentState(Cursor const & cur) const Paragraph const & par = cur.paragraph(); odocstringstream os; - if (buf.params().trackChanges) + if (buf.params().track_changes) os << _("[Change Tracking] "); Change change = par.lookupChange(cur.pos()); @@ -2001,14 +2011,14 @@ docstring Text::asString(pit_type beg, pit_type end, int options) const } -void Text::forToc(docstring & os, size_t maxlen, bool shorten) const +void Text::forOutliner(docstring & os, size_t maxlen, bool shorten) const { 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].forToc(os, maxlen); + pars_[i].forOutliner(os, maxlen); if (shorten && os.length() >= maxlen) os = os.substr(0, maxlen - 3) + from_ascii("..."); } @@ -2056,7 +2066,7 @@ void Text::charsTranspose(Cursor & cur) // And finally, we are ready to perform the transposition. // Track the changes if Change Tracking is enabled. - bool const trackChanges = cur.buffer()->params().trackChanges; + bool const trackChanges = cur.buffer()->params().track_changes; cur.recordUndo(); @@ -2109,7 +2119,7 @@ bool Text::completionSupported(Cursor const & cur) const CompletionList const * Text::createCompletionList(Cursor const & cur) const { - WordList const * list = theWordList(*cur.getFont().language()); + WordList const * list = theWordList(cur.getFont().language()->lang()); return new TextCompletionList(cur, list); }