+ // There are two cases: cutbuffer only one paragraph or many
+ if (!buf->next_) {
+ // only within a paragraph
+ tmpbuf = buf->Clone();
+ // Some provisions should be done here for checking
+ // if we are inserting at the beginning of a
+ // paragraph. If there are a space at the beginning
+ // of the text to insert and we are inserting at
+ // the beginning of the paragraph the space should
+ // be removed.
+ while (buf->size()) {
+ // This is an attempt to fix the
+ // "never insert a space at the
+ // beginning of a paragraph" problem.
+ if (!tmppos && buf->IsLineSeparator(0)) {
+ buf->Erase(0);
+ } else {
+ buf->CutIntoMinibuffer(current_view->buffer()->params, 0);
+ buf->Erase(0);
+ if (tmppar->InsertFromMinibuffer(tmppos))
+ ++tmppos;
+ }
+ }
+ delete buf;
+ buf = tmpbuf;
+ *endpar = tmppar->next();
+ pos = tmppos;
+ } else {
+ // many paragraphs
+
+ // make a copy of the simple cut_buffer
+ tmpbuf = buf;
+ LyXParagraph * simple_cut_clone = tmpbuf->Clone();
+ LyXParagraph * tmpbuf2 = simple_cut_clone;
+ if ((*par)->footnoteflag) {
+ tmpbuf->footnoteflag = (*par)->footnoteflag;
+ tmpbuf->footnotekind = (*par)->footnotekind;
+ }
+ while (tmpbuf->next_) {
+ tmpbuf = tmpbuf->next_;
+ tmpbuf2->next(tmpbuf->Clone());
+ tmpbuf2->next_->previous(tmpbuf2);
+ tmpbuf2 = tmpbuf2->next_;
+ if ((*par)->footnoteflag){
+ tmpbuf->footnoteflag = (*par)->footnoteflag;
+ tmpbuf->footnotekind = (*par)->footnotekind;
+ }
+ }
+
+ // make sure there is no class difference
+ SwitchLayoutsBetweenClasses(textclass, tc, buf);
+
+ // make the buf exactly the same layout than
+ // the cursor paragraph
+ buf->MakeSameLayout(*par);
+
+ // find the end of the buffer
+ LyXParagraph * lastbuffer = buf;
+ while (lastbuffer->next())
+ lastbuffer = lastbuffer->next();
+
+ bool paste_the_end = false;
+
+ // open the paragraph for inserting the buf
+ // if necessary
+ if (((*par)->Last() > pos) || !(*par)->next()) {
+ (*par)->BreakParagraphConservative(current_view->buffer()->params,
+ pos);
+ paste_the_end = true;
+ }
+ // set the end for redoing later
+ *endpar = (*par)->ParFromPos(pos)->next_->next();
+
+ // paste it!
+ lastbuffer->ParFromPos(lastbuffer->Last())->next(
+ (*par)->ParFromPos(pos)->next_);
+ (*par)->ParFromPos(pos)->next()->previous(
+ lastbuffer->ParFromPos(lastbuffer->Last()));
+
+ (*par)->ParFromPos(pos)->next(buf);
+ buf->previous((*par)->ParFromPos(pos));
+
+ if ((*par)->ParFromPos(pos)->next() == lastbuffer)
+ lastbuffer = *par;
+
+ (*par)->ParFromPos(pos)->PasteParagraph(current_view->buffer()->params);
+ // store the new cursor position
+ *par = lastbuffer;
+ pos = lastbuffer->Last();
+ // maybe some pasting
+ if (lastbuffer->next() && paste_the_end) {
+ if (lastbuffer->next()->HasSameLayout(lastbuffer)) {
+ lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(current_view->buffer()->params);
+ } else if (!lastbuffer->next()->Last()) {
+ lastbuffer->next()->MakeSameLayout(lastbuffer);
+ lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(current_view->buffer()->params);
+ } else if (!lastbuffer->Last()) {
+ lastbuffer->MakeSameLayout(lastbuffer->next_);
+ lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(current_view->buffer()->params);
+ } else
+ lastbuffer->next()->StripLeadingSpaces(tc);
+ }
+ // restore the simple cut buffer
+ buf = simple_cut_clone;