X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=ae2434239c1a537a6ae3f92b26565582770bc285;hb=5333998570902b22c3db30af63ddbe8d91304310;hp=ab5aeb95ebd0b96cb1b613508119dfbfc58cc435;hpb=b6f0c1de3d31b33452ad87a3a416731907e3c52e;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index ab5aeb95eb..ae2434239c 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -445,10 +445,10 @@ public: return; } pos_type endpos = last; - owner_->locateWord(first, endpos, WHOLE_WORD); + owner_->locateWord(first, endpos, WHOLE_WORD, true); if (endpos < last) { endpos = last; - owner_->locateWord(last, endpos, WHOLE_WORD); + owner_->locateWord(last, endpos, WHOLE_WORD, true); } last = endpos; } @@ -581,18 +581,6 @@ void Paragraph::addChangesToToc(DocIterator const & cdit, Buffer const & buf, } -void Paragraph::addChangesToBuffer(Buffer const & buf) const -{ - d->changes_.updateBuffer(buf); -} - - -bool Paragraph::isChangeUpdateRequired() const -{ - return d->changes_.isUpdateRequired(); -} - - bool Paragraph::isDeleted(pos_type start, pos_type end) const { LASSERT(start >= 0 && start <= size(), return false); @@ -610,6 +598,28 @@ bool Paragraph::isChanged(pos_type start, pos_type end) const return d->changes_.isChanged(start, end); } +// FIXME: Ideally the diverse isChanged() methods should account for that! +bool Paragraph::hasChangedInsets(pos_type start, pos_type end) const +{ + LASSERT(start >= 0 && start <= size(), return false); + LASSERT(end > start && end <= size() + 1, return false); + + for (auto const icit : d->insetlist_) { + if (icit.pos < start) + continue; + if (icit.pos >= end) + break; + if (icit.inset && icit.inset->isChanged()) + return true; + } + return false; +} + +bool Paragraph::isChanged() const +{ + return d->changes_.isChanged(); +} + bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const { @@ -621,6 +631,11 @@ bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const return change.inserted() && change.currentAuthor(); } +Change Paragraph::parEndChange() const +{ + return d->changes_.lookup(size()); +} + void Paragraph::setChange(Change const & change) { @@ -655,8 +670,8 @@ void Paragraph::setChange(pos_type pos, Change const & change) // see comment in setChange(Change const &) above if (!change.deleted() && pos < size()) - if (Inset * inset = getInset(pos)) - inset->setChange(change); + if (Inset * inset = getInset(pos)) + inset->setChange(change); } @@ -1005,7 +1020,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams, bool close = false; odocstream::pos_type const len = os.os().tellp(); - if (inset->forceLTR() + if (inset->forceLTR(runparams) && running_font.isRightToLeft() // ERT is an exception, it should be output with no // decorations at all @@ -1860,8 +1875,9 @@ char_type Paragraph::getUChar(BufferParams const & bparams, char_type c = d->text_[pos]; // Return unchanged character in LTR languages - // or if we use poylglossia/bidi. - if (rp.use_polyglossia || !getFontSettings(bparams, pos).isRightToLeft()) + // or if we use poylglossia/bidi (XeTeX). + if (rp.useBidiPackage() + || !getFontSettings(bparams, pos).isRightToLeft()) return c; // Without polyglossia/bidi, we need to account for some special cases. @@ -1880,7 +1896,8 @@ char_type Paragraph::getUChar(BufferParams const & bparams, char_type uc = c; // 1. In the following languages, parentheses need to be reversed. - bool const reverseparens = lang == "hebrew"; + // Also with polyglodia/luabidi + bool const reverseparens = (lang == "hebrew" || rp.use_polyglossia); // 2. In the following languages, brackets don't need to be reversed. bool const reversebrackets = lang != "arabic_arabtex" @@ -2105,15 +2122,17 @@ void Paragraph::setBeginOfBody() // remove unnecessary getChar() calls pos_type i = 0; pos_type end = size(); - if (i < end && !(isNewline(i) || isEnvSeparator(i))) { + bool prev_char_deleted = false; + if (i < end && (!(isNewline(i) || isEnvSeparator(i)) || isDeleted(i))) { ++i; if (i < end) { char_type previous_char = d->text_[i]; if (!(isNewline(i) || isEnvSeparator(i))) { ++i; - while (i < end && previous_char != ' ') { + while (i < end && (previous_char != ' ' || prev_char_deleted)) { char_type temp = d->text_[i]; - if (isNewline(i) || isEnvSeparator(i)) + prev_char_deleted = isDeleted(i); + if (!isDeleted(i) && (isNewline(i) || isEnvSeparator(i))) break; ++i; previous_char = temp; @@ -2245,8 +2264,9 @@ int Paragraph::Private::startTeXParParams(BufferParams const & bparams, InsetCode code = ownerCode(); bool const lastpar = runparams.isLastPar; // RTL in classic (PDF)LaTeX (without the Bidi package) + // Luabibdi (used by LuaTeX) behaves like classic bool const rtl_classic = owner_->getParLanguage(bparams)->rightToLeft() - && !runparams.use_polyglossia; + && !runparams.useBidiPackage(); switch (curAlign) { case LYX_ALIGN_NONE: @@ -2308,8 +2328,9 @@ bool Paragraph::Private::endTeXParParams(BufferParams const & bparams, InsetCode code = ownerCode(); bool const lastpar = runparams.isLastPar; // RTL in classic (PDF)LaTeX (without the Bidi package) + // Luabibdi (used by LuaTeX) behaves like classic bool const rtl_classic = owner_->getParLanguage(bparams)->rightToLeft() - && !runparams.use_polyglossia; + && !runparams.useBidiPackage(); switch (curAlign) { case LYX_ALIGN_NONE: @@ -2468,9 +2489,14 @@ void Paragraph::latex(BufferParams const & bparams, Change const & change = runparams.inDeletedInset ? runparams.changeOfDeletedInset : lookupChange(i); + char_type const c = d->text_[i]; + // Check whether a display math inset follows - if (d->text_[i] == META_INSET + if (c == META_INSET && i >= start_pos && (end_pos == -1 || i < end_pos)) { + if (isDeleted(i)) + runparams.ctObject = getInset(i)->CtObject(runparams); + InsetMath const * im = getInset(i)->asInsetMath(); if (im && im->asHullInset() && im->asHullInset()->outerDisplay()) { @@ -2496,7 +2522,8 @@ void Paragraph::latex(BufferParams const & bparams, basefont, needPar); open_font = false; } - basefont = getLayoutFont(bparams, outerfont); + basefont = (body_pos > i) ? getLabelFont(bparams, outerfont) + : getLayoutFont(bparams, outerfont); running_font = basefont; column += Changes::latexMarkChange(os, bparams, Change(Change::INSERTED), change, rp); @@ -2516,7 +2543,8 @@ void Paragraph::latex(BufferParams const & bparams, basefont, basefont, needPar); open_font = false; } - basefont = getLayoutFont(bparams, outerfont); + basefont = (body_pos > i) ? getLabelFont(bparams, outerfont) + : getLayoutFont(bparams, outerfont); running_font = basefont; column += Changes::latexMarkChange(os, bparams, runningChange, change, runparams); @@ -2582,8 +2610,6 @@ void Paragraph::latex(BufferParams const & bparams, } } - char_type const c = d->text_[i]; - // A display math inset inside an ulem command will be output // as a box of width \linewidth, so we have to either disable // indentation if the inset starts a paragraph, or start a new @@ -2602,6 +2628,21 @@ void Paragraph::latex(BufferParams const & bparams, current_font.language() != running_font.language()) && i != body_pos - 1) { + bool const in_ct_deletion = (bparams.output_changes + && runningChange == change + && change.type == Change::DELETED + && !os.afterParbreak()); + if (in_ct_deletion) { + // We have to close and then reopen \lyxdeleted, + // as strikeout needs to be on lowest level. + bool needPar = false; + OutputParams rp = runparams; + column += running_font.latexWriteEndChanges( + os, bparams, rp, basefont, + basefont, needPar); + os << '}'; + column += 1; + } odocstringstream ods; column += current_font.latexWriteStartChanges(ods, bparams, runparams, basefont, @@ -2630,6 +2671,13 @@ void Paragraph::latex(BufferParams const & bparams, << from_ascii("{}"); else os << fontchange; + if (in_ct_deletion) { + // We have to close and then reopen \lyxdeleted, + // as strikeout needs to be on lowest level. + OutputParams rp = runparams; + column += Changes::latexMarkChange(os, bparams, + Change(Change::UNCHANGED), change, rp); + } } // FIXME: think about end_pos implementation... @@ -2696,6 +2744,16 @@ void Paragraph::latex(BufferParams const & bparams, runningChange, style, i, column); if (incremented) --parInline; + + if (runparams.ctObject == OutputParams::CT_DISPLAYOBJECT + || runparams.ctObject == OutputParams::CT_UDISPLAYOBJECT) { + // Close \lyx*deleted and force its + // reopening (if needed) + os << '}'; + column++; + runningChange = Change(Change::UNCHANGED); + runparams.ctObject = OutputParams::CT_NORMAL; + } } } else if (i >= start_pos && (end_pos == -1 || i < end_pos)) { if (!bparams.useNonTeXFonts) @@ -2744,7 +2802,7 @@ void Paragraph::latex(BufferParams const & bparams, runparams.post_macro = rp.post_macro; } - // Close wrapper for alien script + // Close wrapper for alien script if (!alien_script.empty()) { os << "}"; alien_script.clear(); @@ -3382,10 +3440,12 @@ bool Paragraph::isLineSeparator(pos_type pos) const } -bool Paragraph::isWordSeparator(pos_type pos) const +bool Paragraph::isWordSeparator(pos_type pos, bool const ignore_deleted) const { if (pos == size()) return true; + if (ignore_deleted && isDeleted(pos)) + return false; if (Inset const * inset = getInset(pos)) return !inset->isLetter(); // if we have a hard hyphen (no en- or emdash) or apostrophe @@ -3989,13 +4049,13 @@ void Paragraph::deregisterWords() void Paragraph::locateWord(pos_type & from, pos_type & to, - word_location const loc) const + word_location const loc, bool const ignore_deleted) const { switch (loc) { case WHOLE_WORD_STRICT: if (from == 0 || from == size() - || isWordSeparator(from) - || isWordSeparator(from - 1)) { + || isWordSeparator(from, ignore_deleted) + || isWordSeparator(from - 1, ignore_deleted)) { to = from; return; } @@ -4003,13 +4063,13 @@ void Paragraph::locateWord(pos_type & from, pos_type & to, case WHOLE_WORD: // If we are already at the beginning of a word, do nothing - if (!from || isWordSeparator(from - 1)) + if (!from || isWordSeparator(from - 1, ignore_deleted)) break; // fall through case PREVIOUS_WORD: // always move the cursor to the beginning of previous word - while (from && !isWordSeparator(from - 1)) + while (from && !isWordSeparator(from - 1, ignore_deleted)) --from; break; case NEXT_WORD: @@ -4020,7 +4080,7 @@ void Paragraph::locateWord(pos_type & from, pos_type & to, break; } to = from; - while (to < size() && !isWordSeparator(to)) + while (to < size() && !isWordSeparator(to, ignore_deleted)) ++to; } @@ -4200,7 +4260,7 @@ SpellChecker::Result Paragraph::spellCheck(pos_type & from, pos_type & to, if (!d->layout_->spellcheck || !inInset().allowSpellCheck()) return result; - locateWord(from, to, WHOLE_WORD); + locateWord(from, to, WHOLE_WORD, true); if (from == to || from >= size()) return result;