]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
More requires --> required, for C++2a.
[lyx.git] / src / Paragraph.cpp
index 311e9528070f7cf0dfe23ade396091b36d741dac..710587bb578a4a736420b7eac727032dc30f7b76 100644 (file)
@@ -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);
@@ -611,6 +599,12 @@ bool Paragraph::isChanged(pos_type start, pos_type end) const
 }
 
 
+bool Paragraph::isChanged() const
+{
+       return d->changes_.isChanged();
+}
+
+
 bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
 {
        // keep the logic here in sync with the logic of eraseChars()
@@ -621,6 +615,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 +654,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);
 }
 
 
@@ -2472,9 +2471,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()) {
@@ -2500,7 +2504,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);
@@ -2520,7 +2525,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);
@@ -2586,8 +2592,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
@@ -2606,6 +2610,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,
@@ -2634,6 +2653,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...
@@ -2700,6 +2726,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)
@@ -2748,7 +2784,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();
@@ -3386,10 +3422,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
@@ -3993,13 +4031,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;
                }
@@ -4007,13 +4045,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:
@@ -4024,7 +4062,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;
 }
 
@@ -4204,7 +4242,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;