From: Jean-Marc Lasgouttes Date: Wed, 3 Apr 2019 09:06:43 +0000 (+0200) Subject: Put end label on own row after display inset X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=aaf055d31f2d81045ebd17fbbc7d8acd84462090;p=features.git Put end label on own row after display inset This corresponds to what is done on display. The same should be done for start label too (e.g. beginning of a proof), but this requires more work. This required to move the static function getEndLabel to Text. Fixes bug #11536. --- diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp index a88ac2a6be..a486c0e97e 100644 --- a/src/RowPainter.cpp +++ b/src/RowPainter.cpp @@ -472,41 +472,9 @@ void RowPainter::paintTopLevelLabel() const } -/** Check if the current paragraph is the last paragraph in a - proof environment */ -static int getEndLabel(pit_type p, Text const & text) -{ - ParagraphList const & pars = text.paragraphs(); - pit_type pit = p; - depth_type par_depth = pars[p].getDepth(); - while (pit != pit_type(pars.size())) { - Layout const & layout = pars[pit].layout(); - int const endlabeltype = layout.endlabeltype; - - if (endlabeltype != END_LABEL_NO_LABEL) { - if (p + 1 == pit_type(pars.size())) - return endlabeltype; - - depth_type const next_depth = - pars[p + 1].getDepth(); - if (par_depth > next_depth || - (par_depth == next_depth && layout != pars[p + 1].layout())) - return endlabeltype; - break; - } - if (par_depth == 0) - break; - pit = text.outerHook(pit); - if (pit != pit_type(pars.size())) - par_depth = pars[pit].getDepth(); - } - return END_LABEL_NO_LABEL; -} - - void RowPainter::paintLast() const { - int const endlabel = getEndLabel(row_.pit(), text_); + int const endlabel = text_.getEndLabel(row_.pit()); switch (endlabel) { case END_LABEL_BOX: case END_LABEL_FILLED_BOX: { diff --git a/src/Text.cpp b/src/Text.cpp index c3c2108472..98cedccf9c 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -288,6 +288,35 @@ Font const Text::outerFont(pit_type par_offset) const } +int Text::getEndLabel(pit_type p) const +{ + pit_type pit = p; + depth_type par_depth = pars_[p].getDepth(); + while (pit != pit_type(pars_.size())) { + Layout const & layout = pars_[pit].layout(); + int const endlabeltype = layout.endlabeltype; + + if (endlabeltype != END_LABEL_NO_LABEL) { + if (p + 1 == pit_type(pars_.size())) + return endlabeltype; + + depth_type const next_depth = + pars_[p + 1].getDepth(); + if (par_depth > next_depth || + (par_depth == next_depth && layout != pars_[p + 1].layout())) + return endlabeltype; + break; + } + if (par_depth == 0) + break; + pit = outerHook(pit); + if (pit != pit_type(pars_.size())) + par_depth = pars_[pit].getDepth(); + } + return END_LABEL_NO_LABEL; +} + + static void acceptOrRejectChanges(ParagraphList & pars, BufferParams const & bparams, Text::ChangeOp op) { diff --git a/src/Text.h b/src/Text.h index f3cd8447f5..dc96d839bb 100644 --- a/src/Text.h +++ b/src/Text.h @@ -345,6 +345,8 @@ public: /// Get the font of the "environment" of paragraph \p par_offset in \p pars. /// All font changes of the paragraph are relative to this font. Font const outerFont(pit_type pit_offset) const; + /// Return the label type at the end of paragraph \c pit. + int getEndLabel(pit_type pit) const; private: /// The InsetText owner shall have access to everything. diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 9bb116d360..6ce580c60c 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -983,11 +983,17 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const Inset const * inset = 0; if (par.isNewline(i) || par.isEnvSeparator(i) || (i + 1 < end && (inset = par.getInset(i + 1)) - && inset->display()) + && inset->display()) || (!row.empty() && row.back().inset - && row.back().inset->display())) { + && row.back().inset->display())) { row.flushed(true); - need_new_row = par.isNewline(i); + // We will force a row creation after either + // - a newline; + // - a display inset followed by a end label. + need_new_row = + par.isNewline(i) + || (inset->display() && i + 1 == end + && text_->getEndLabel(row.pit()) != END_LABEL_NO_LABEL); ++i; break; }