+ //There was an InsetBibitem at the beginning, and we didn't
+ //have to erase one.
+ if (hasbibitem && erasedInsetPosition < 0)
+ return 0;
+
+ //There was an InsetBibitem at the beginning and we did have to
+ //erase one. So we give its properties to the beginning inset.
+ if (hasbibitem) {
+ InsetBibitem * inset =
+ static_cast<InsetBibitem *>(insetlist.begin()->inset);
+ if (!oldkey.empty())
+ inset->setParam("key", oldkey);
+ inset->setParam("label", oldlabel);
+ return -erasedInsetPosition;
+ }
+
+ //There was no inset at the beginning, so we need to create one with
+ //the key and label of the one we erased.
+ InsetBibitem * inset(new InsetBibitem(InsetCommandParams("bibitem")));
+ // restore values of previously deleted item in this par.
+ if (!oldkey.empty())
+ inset->setParam("key", oldkey);
+ inset->setParam("label", oldlabel);
+ insertInset(0, static_cast<Inset *>(inset),
+ Change(track_changes ? Change::INSERTED : Change::UNCHANGED));
+
+ return 1;