Simplify function

(cherry picked from commit 9fc1194494)
This commit is contained in:
Juergen Spitzmueller 2024-07-30 15:30:41 +02:00
parent 173464b8a3
commit 608e678217

View File

@ -1657,7 +1657,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
case LFUN_REFERENCE_TO_PARAGRAPH: { case LFUN_REFERENCE_TO_PARAGRAPH: {
vector<string> const pids = getVectorFromString(cmd.getArg(0)); vector<string> const pids = getVectorFromString(cmd.getArg(0));
string const type = cmd.getArg(1); string const type = cmd.getArg(1);
int id = convert<int>(pids.front()); int id = convert<int>(pids.back());
if (id < 0) if (id < 0)
break; break;
int i = 0; int i = 0;
@ -1676,8 +1676,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
lyx::dispatch(FuncRequest(LFUN_REFERENCE_INSERT, arg)); lyx::dispatch(FuncRequest(LFUN_REFERENCE_INSERT, arg));
break; break;
} else { } else {
// if there is not a label yet, or we do not see it // if there is not a label yet
// (since it is in a different buffer),
// go to the paragraph (including nested insets) ... // go to the paragraph (including nested insets) ...
lyx::dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0")); lyx::dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
for (string const & s : pids) { for (string const & s : pids) {
@ -1687,24 +1686,16 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
dit = b->getParFromID(id); dit = b->getParFromID(id);
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, s)); lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, s));
} }
// ... and try again if we find a label ... // ... if not, insert a new label
label = dit.innerParagraph().getLabelForXRef(); // we do not want to open the dialog, hence we
string arg; // do not employ LFUN_LABEL_INSERT
if (!label.empty()) { InsetCommandParams p(LABEL_CODE);
// if the paragraph has a label, we refer to this docstring const new_label = dit.getPossibleLabel();
arg = (type.empty()) ? label : label + " " + type; p["name"] = new_label;
} else { string const data = InsetCommand::params2string(p);
// ... if not, insert a new label lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
// we do not want to open the dialog, hence we string const arg = (type.empty()) ? to_utf8(new_label)
// do not employ LFUN_LABEL_INSERT : to_utf8(new_label) + " " + type;
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;
}
// ... and go back to the original position // ... and go back to the original position
lyx::dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0")); lyx::dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
// ... to insert the ref // ... to insert the ref