]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Properly close and reopen lyxdeleted macro at font change
[lyx.git] / src / Paragraph.cpp
index 27d1230f97d9f7e637f28113478f8e924e626484..bfae1fc67d049e06d815a1f08ba85ee8af67a116 100644 (file)
@@ -516,7 +516,7 @@ public:
 
 
 Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
-       : owner_(owner), inset_owner_(0), id_(-1), begin_of_body_(0), layout_(&layout)
+       : owner_(owner), inset_owner_(nullptr), id_(-1), begin_of_body_(0), layout_(&layout)
 {
        text_.reserve(100);
 }
@@ -604,14 +604,12 @@ 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);
 
-       InsetList::const_iterator icit = d->insetlist_.begin();
-       InsetList::const_iterator iend = d->insetlist_.end();
-       for (; icit != iend; ++icit) {
-               if (icit->pos < start)
+       for (auto const & icit : d->insetlist_) {
+               if (icit.pos < start)
                        continue;
-               if (icit->pos >= end)
+               if (icit.pos >= end)
                        break;
-               if (icit->inset && icit->inset->isChanged())
+               if (icit.inset && icit.inset->isChanged())
                        return true;
        }
        return false;
@@ -1766,7 +1764,7 @@ Font const & Paragraph::getFontSettings(BufferParams const & bparams,
        // Optimisation: avoid a full font instantiation if there is no
        // language change from previous call.
        static Font previous_font;
-       static Language const * previous_lang = 0;
+       static Language const * previous_lang = nullptr;
        Language const * lang = getParLanguage(bparams);
        if (lang != previous_lang) {
                previous_lang = lang;
@@ -1814,7 +1812,7 @@ Font const & Paragraph::getFirstFontSettings(BufferParams const & bparams) const
        // Optimisation: avoid a full font instantiation if there is no
        // language change from previous call.
        static Font previous_font;
-       static Language const * previous_lang = 0;
+       static Language const * previous_lang = nullptr;
        if (bparams.language != previous_lang) {
                previous_lang = bparams.language;
                previous_font = Font(inherit_font, bparams.language);
@@ -2124,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;
@@ -2563,6 +2563,10 @@ void Paragraph::latex(BufferParams const & bparams,
                Font const current_font = getFont(bparams, i, outerfont);
 
                Font const last_font = running_font;
+               bool const in_ct_deletion = (bparams.output_changes
+                                 && runningChange == change
+                                 && change.type == Change::DELETED
+                                 && !os.afterParbreak());
 
                // Do we need to close the previous font?
                if (open_font &&
@@ -2576,10 +2580,23 @@ void Paragraph::latex(BufferParams const & bparams,
                                alien_script.clear();
                        }
                        bool needPar = false;
+                       if (in_ct_deletion) {
+                               // We have to close and then reopen \lyxdeleted,
+                               // as strikeout needs to be on lowest level.
+                               os << '}';
+                               column += 1;
+                       }
                        column += running_font.latexWriteEndChanges(
                                    os, bparams, runparams, basefont,
                                    (i == body_pos-1) ? basefont : current_font,
                                    needPar);
+                       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(Change::DELETED), rp);
+                       }
                        running_font = basefont;
                        open_font = false;
                }
@@ -2625,13 +2642,9 @@ void Paragraph::latex(BufferParams const & bparams,
 
                // Do we need to change font?
                if ((current_font != running_font ||
-                    current_font.language() != running_font.language()) &&
-                       i != body_pos - 1)
+                    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.
@@ -2719,7 +2732,7 @@ void Paragraph::latex(BufferParams const & bparams,
                                Inset const * inset = getInset(i);
                                InsetText const * textinset = inset
                                                        ? inset->asInsetText()
-                                                       : 0;
+                                                       : nullptr;
                                if (i + 1 == size() && textinset
                                    && !inset->getLayout().isDisplay()) {
                                        ParagraphList const & pars =
@@ -3638,7 +3651,7 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out
                        os.put(c);
                else if (c == META_INSET && (options & AS_STR_INSETS)) {
                        if (c == META_INSET && (options & AS_STR_PLAINTEXT)) {
-                               LASSERT(runparams != 0, return docstring());
+                               LASSERT(runparams != nullptr, return docstring());
                                getInset(i)->plaintext(os, *runparams);
                        } else {
                                getInset(i)->toString(os);
@@ -3885,14 +3898,14 @@ Inset * Paragraph::releaseInset(pos_type pos)
 Inset * Paragraph::getInset(pos_type pos)
 {
        return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET)
-                ? d->insetlist_.get(pos) : 0;
+                ? d->insetlist_.get(pos) : nullptr;
 }
 
 
 Inset const * Paragraph::getInset(pos_type pos) const
 {
        return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET)
-                ? d->insetlist_.get(pos) : 0;
+                ? d->insetlist_.get(pos) : nullptr;
 }
 
 
@@ -4159,7 +4172,7 @@ Language * Paragraph::Private::locateSpellRange(
                ++from;
        // don't check empty range
        if (from >= to)
-               return 0;
+               return nullptr;
        // get current language
        Language * lang = getSpellLanguage(from);
        pos_type last = from;