From a936bc2df57cef9545f642e6dfdb7afa3eed4b81 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 25 Jan 2019 14:40:30 +0100 Subject: [PATCH] Do not check for duplicates when pasting a label into a non-outputting inset. Issue mentioned at #10333 --- src/CutAndPaste.cpp | 17 +++++++++++++++-- src/insets/InsetLabel.cpp | 5 +++-- src/insets/InsetLabel.h | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 0f269b27e4..c71697ffda 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -125,6 +125,19 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, if (parlist.empty()) return PasteReturnValue(pit, pos, need_update); + // Check whether we paste into an inset that does not + // produce output (needed for label duplicate check) + bool in_active_inset = cur.paragraph().inInset().producesOutput(); + if (in_active_inset) { + for (size_type sl = 0 ; sl < cur.depth() ; ++sl) { + Paragraph const & outer_par = cur[sl].paragraph(); + if (!outer_par.inInset().producesOutput()) { + in_active_inset = false; + break; + } + } + } + InsetText * target_inset = cur.inset().asInsetText(); if (!target_inset) { InsetTabular * it = cur.inset().asInsetTabular(); @@ -305,7 +318,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, continue; InsetLabel * lab = labels[i]; docstring const oldname = lab->getParam("name"); - lab->updateLabel(oldname); + lab->updateLabel(oldname, in_active_inset); // We need to update the buffer reference cache. need_update = true; docstring const newname = lab->getParam("name"); @@ -336,7 +349,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, // check for duplicates InsetLabel & lab = static_cast(*it); docstring const oldname = lab.getParam("name"); - lab.updateLabel(oldname); + lab.updateLabel(oldname, in_active_inset); // We need to update the buffer reference cache. need_update = true; docstring const newname = lab.getParam("name"); diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 768d8293dc..e325f1ea94 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -82,10 +82,11 @@ void InsetLabel::uniqueLabel(docstring & label) const } -void InsetLabel::updateLabel(docstring const & new_label) +void InsetLabel::updateLabel(docstring const & new_label, bool const active) { docstring label = new_label; - uniqueLabel(label); + if (active) + uniqueLabel(label); setParam("name", label); } diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index 22131ab4a1..92c3380f70 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -32,7 +32,7 @@ public: /// docstring const & prettyCounter() const { return pretty_counter_; } /// Updates only the label string, doesn't handle undo nor references. - void updateLabel(docstring const & new_label); + void updateLabel(docstring const & new_label, bool const active = true); /// Updates the label and the references to it. /// Will also handle undo/redo if \p cursor is passed. void updateLabelAndRefs(docstring const & new_label, Cursor * cursor = 0); -- 2.39.2