From 608e678217ddbb7b859a660978ce1d61887e017c Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 30 Jul 2024 15:30:41 +0200 Subject: [PATCH] Amend 9464f0526ef Simplify function (cherry picked from commit 9fc11944947d020d7fcb949d8df548e61ad425a5) --- src/BufferView.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 56b5ca6c02..ff62bd2af5 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1657,7 +1657,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_REFERENCE_TO_PARAGRAPH: { vector const pids = getVectorFromString(cmd.getArg(0)); string const type = cmd.getArg(1); - int id = convert(pids.front()); + int id = convert(pids.back()); if (id < 0) break; int i = 0; @@ -1676,8 +1676,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) lyx::dispatch(FuncRequest(LFUN_REFERENCE_INSERT, arg)); break; } else { - // if there is not a label yet, or we do not see it - // (since it is in a different buffer), + // if there is not a label yet // go to the paragraph (including nested insets) ... lyx::dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0")); for (string const & s : pids) { @@ -1687,24 +1686,16 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) dit = b->getParFromID(id); lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, s)); } - // ... and try again if we find a label ... - label = dit.innerParagraph().getLabelForXRef(); - string arg; - if (!label.empty()) { - // if the paragraph has a label, we refer to this - arg = (type.empty()) ? label : label + " " + type; - } else { - // ... if not, insert a new label - // we do not want to open the dialog, hence we - // do not employ LFUN_LABEL_INSERT - InsetCommandParams p(LABEL_CODE); - docstring const new_label = dit.getPossibleLabel(); - p["name"] = new_label; - string const data = InsetCommand::params2string(p); - lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data)); - arg = (type.empty()) ? to_utf8(new_label) - : to_utf8(new_label) + " " + type; - } + // ... if not, insert a new label + // we do not want to open the dialog, hence we + // do not employ LFUN_LABEL_INSERT + InsetCommandParams p(LABEL_CODE); + docstring const new_label = dit.getPossibleLabel(); + p["name"] = new_label; + string const data = InsetCommand::params2string(p); + lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data)); + string const arg = (type.empty()) ? to_utf8(new_label) + : to_utf8(new_label) + " " + type; // ... and go back to the original position lyx::dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0")); // ... to insert the ref