From 7d0b7e0840dcaf31d15cd9ecd83edba10879252b Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sat, 15 Apr 2017 22:47:11 -0400 Subject: [PATCH] Fix for #10624. If we're in the first paragraph after a division (section, etc), use the prefix for it. (cherry picked from commit dd2efe8d0d1fb7070c4fa0cbcb52f15a48bec33b) --- src/Text.cpp | 71 ++++++++++++++++++++++++++-------------------------- status.23x | 3 +++ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/Text.cpp b/src/Text.cpp index ed3650b8df..5b8fc9a8d8 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1972,12 +1972,44 @@ docstring Text::currentState(Cursor const & cur, bool devel_mode) const docstring Text::getPossibleLabel(Cursor const & cur) const { - pit_type pit = cur.pit(); + pit_type textpit = cur.pit(); + Layout const * layout = &(pars_[textpit].layout()); - Layout const * layout = &(pars_[pit].layout()); + // Will contain the label prefix. + docstring name; + + // For captions, we just take the caption type + Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE); + if (caption_inset) { + string const & ftype = static_cast(caption_inset)->floattype(); + FloatList const & fl = cur.buffer()->params().documentClass().floats(); + if (fl.typeExist(ftype)) { + Floating const & flt = fl.getType(ftype); + name = from_utf8(flt.refPrefix()); + } + if (name.empty()) + name = from_utf8(ftype.substr(0,3)); + } else { + // For section, subsection, etc... + if (layout->latextype == LATEX_PARAGRAPH && textpit != 0) { + Layout const * layout2 = &(pars_[textpit - 1].layout()); + if (layout2->latextype != LATEX_PARAGRAPH) { + --textpit; + layout = layout2; + } + } + if (layout->latextype != LATEX_PARAGRAPH) + name = layout->refprefix; + + // If none of the above worked, see if the inset knows. + if (name.empty()) { + InsetLayout const & il = cur.inset().getLayout(); + name = il.refprefix(); + } + } docstring text; - docstring par_text = pars_[pit].asString(AS_STR_SKIPDELETE); + docstring par_text = pars_[textpit].asString(AS_STR_SKIPDELETE); // The return string of math matrices might contain linebreaks par_text = subst(par_text, '\n', '-'); @@ -1998,39 +2030,6 @@ docstring Text::getPossibleLabel(Cursor const & cur) const if (text.size() > max_label_length) text.resize(max_label_length); - // Will contain the label prefix. - docstring name; - - // For section, subsection, etc... - if (layout->latextype == LATEX_PARAGRAPH && pit != 0) { - Layout const * layout2 = &(pars_[pit - 1].layout()); - if (layout2->latextype != LATEX_PARAGRAPH) { - --pit; - layout = layout2; - } - } - if (layout->latextype != LATEX_PARAGRAPH) - name = layout->refprefix; - - // For captions, we just take the caption type - Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE); - if (caption_inset) { - string const & ftype = static_cast(caption_inset)->floattype(); - FloatList const & fl = cur.buffer()->params().documentClass().floats(); - if (fl.typeExist(ftype)) { - Floating const & flt = fl.getType(ftype); - name = from_utf8(flt.refPrefix()); - } - if (name.empty()) - name = from_utf8(ftype.substr(0,3)); - } - - // If none of the above worked, see if the inset knows. - if (name.empty()) { - InsetLayout const & il = cur.inset().getLayout(); - name = il.refprefix(); - } - if (!name.empty()) text = name + ':' + text; diff --git a/status.23x b/status.23x index 970f234013..0ca83fdf41 100644 --- a/status.23x +++ b/status.23x @@ -214,6 +214,9 @@ What's new - Handle math insets properly when inserting index entries (bug 6344). +- When adding a label in the first paragraph after a division (section, + etc), use the label prefix for it (bug 10624). + * INTERNALS