commit 5ef62542990cec69f1e9e5879301eaacb84eaf4e
Author: Juergen Spitzmueller <[email protected]>
Date:   Sun Sep 27 10:15:06 2026 +0200

    Consider in LFUN_REFERENCE_TO_PARAGRAPH that numbered math insets might be 
within a paragraph
    
    We assumed until now that they always start a new paragraph, hence
    label (slots) weren't correctly located
---
 src/BufferView.cpp | 16 ++++++++++++----
 src/TocBuilder.cpp | 15 ++++++++++++---
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 74b106a330..8f9646e736 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1724,6 +1724,11 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                vector<string> const pids = getVectorFromString(cmd.getArg(0));
                string const type = cmd.getArg(1);
                int id = convert<int>(pids.back());
+               pos_type pos = 0;
+               // Argument 1 might be row,pos,parid for mathed.
+               // For texted, we have only parid.
+               if (pids.size() > 2)
+                       pos = convert<size_t>(pids.at(1));
                row_type row = -1;
                inserted_label_.clear();
                if (id < 0)
@@ -1737,10 +1742,13 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                                ++i;
                                continue;
                        }
+                       Inset * ins = dit.nextInset();
+                       if (!dit.inMathed() && pos > 0 && pos <= dit.lastpos())
+                               ins = dit.paragraph().getInset(pos);
                        string label;
-                       if (dit.nextInset() && dit.nextInset()->asInsetMath() 
&& dit.nextInset()->asInsetMath()->asHullInset()) {
+                       if (ins && ins->asInsetMath() && 
ins->asInsetMath()->asHullInset()) {
                                row = convert<row_type>(pids.front());
-                               label = 
to_utf8(dit.nextInset()->asInsetMath()->asHullInset()->label(row));
+                               label = 
to_utf8(ins->asInsetMath()->asHullInset()->label(row));
                        } else
                                label = dit.innerParagraph().getLabelForXRef();
                        if (!label.empty()) {
@@ -1759,7 +1767,7 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                                // if there is not a label yet, insert one
                                // this categorically differs in texted and 
mathed
                                docstring new_label;
-                               if (dit.nextInset() && 
dit.nextInset()->asInsetMath() && 
dit.nextInset()->asInsetMath()->asHullInset()) {
+                               if (ins && ins->asInsetMath() && 
ins->asInsetMath()->asHullInset()) {
                                        // in mathed, we set the label via 
InsetMathHull::label()
                                        // but we need to assure it is unique
                                        new_label = from_ascii("eq:equation");
@@ -1771,7 +1779,7 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                                        // record undo for the math inset next 
to dit
                                        CursorData(dit).recordUndo();
                                        // insert the label to the desired row 
of the hull inset
-                                       
dit.nextInset()->asInsetMath()->asHullInset()->label(row, new_label, true);
+                                       
ins->asInsetMath()->asHullInset()->label(row, new_label, true);
                                        // needed to get the new label into the 
buffer list
                                        cur.buffer()->updateBuffer();
                                } else {
diff --git a/src/TocBuilder.cpp b/src/TocBuilder.cpp
index 458a95db66..a7a75caf2a 100644
--- a/src/TocBuilder.cpp
+++ b/src/TocBuilder.cpp
@@ -17,6 +17,7 @@
 
 #include "support/convert.h"
 #include "support/lassert.h"
+#include "support/lstrings.h"
 
 using namespace std;
 
@@ -105,9 +106,17 @@ void TocBuilder::mathMultilineItem(docstring const & 
arg_str, Toc::size_type row
                (str.empty() || !stack_.top().is_captioned) ? "" :  ", ";
        item.str(str + from_ascii(delim) + arg_str);
        docstring parID = item.parIDs();
-       if (!stack_.empty())
-               parID = 
(*toc_)[stack_.top().pos].dit().paragraphGotoArgument(true);
-       item.setParIDs(convert<docstring>(row) + ',' + parID);
+       docstring pos;
+       if (!stack_.empty()) {
+               vector<docstring> const pidPos =
+                       
support::getVectorFromString((*toc_)[stack_.top().pos].dit().paragraphGotoArgument(),
+                                                    from_ascii(" "));
+               parID = pidPos.front();
+               pos = pidPos.back();
+       }
+       // LFUN_REFERENCE_TO_PARAGRAPH needs row,pos,parID in order to
+       // find the correct place for the label
+       item.setParIDs(convert<docstring>(row)+ ',' + pos + ',' + parID);
        stack_.top().is_captioned = true;
 }
 
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to