- bool hasbibitem = !d->insetlist_.empty()
- // Insist on it being in pos 0
- && d->text_[0] == META_INSET
- && d->insetlist_.begin()->inset->lyxCode() == BIBITEM_CODE;
-
- bool track_changes = buffer.params().trackChanges;
-
- docstring oldkey;
- docstring oldlabel;
-
- // remove a bibitem in pos != 0
- // restore it later in pos 0 if necessary
- // (e.g. if a user inserts contents _before_ the item)
- // we're assuming there's only one of these, which there
- // should be.
- int erasedInsetPosition = -1;
- InsetList::iterator it = d->insetlist_.begin();
- InsetList::iterator end = d->insetlist_.end();
- for (; it != end; ++it)
- if (it->inset->lyxCode() == BIBITEM_CODE
- && it->pos > 0) {
- InsetCommand * olditem = it->inset->asInsetCommand();
- oldkey = olditem->getParam("key");
- oldlabel = olditem->getParam("label");
- erasedInsetPosition = it->pos;
- eraseChar(erasedInsetPosition, track_changes);
- break;
- }
+ bool const track_changes = buffer.params().trackChanges;
+ int bibitem_pos = d->insetlist_.find(BIBITEM_CODE);
+ bool const hasbibitem0 = bibitem_pos == 0;