commit 7d0b7e0840dcaf31d15cd9ecd83edba10879252b
Author: Richard Heck <[email protected]>
Date:   Sat Apr 15 22:47:11 2017 -0400

    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 ed3650b..5b8fc9a 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());
+
+       // Will contain the label prefix.
+       docstring name;
 
-       Layout const * layout = &(pars_[pit].layout());
+       // For captions, we just take the caption type
+       Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE);
+       if (caption_inset) {
+               string const & ftype = static_cast<InsetCaption 
*>(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<InsetCaption 
*>(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 970f234..0ca83fd 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
 

Reply via email to