- (*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;
- }
-#else
- // open the paragraph for inserting the buf
- // if necessary
- if (((*par)->size() > pos) || !(*par)->next()) {
- (*par)->BreakParagraphConservative(current_view->buffer()->params,
- pos);
- paste_the_end = true;
+ // There are two cases: cutbuffer only one paragraph or many
+ if (!buf->next()) {
+ // only within a paragraph
+ Paragraph * tmpbuf = new Paragraph(*buf, false);
+
+ // 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
+ Paragraph * tmpbuf = buf;
+ Paragraph * simple_cut_clone = new Paragraph(*tmpbuf, false);
+ Paragraph * tmpbuf2 = simple_cut_clone;
+
+ while (tmpbuf->next()) {
+ tmpbuf = tmpbuf->next();
+ tmpbuf2->next(new Paragraph(*tmpbuf, false));
+ tmpbuf2->next()->previous(tmpbuf2);
+ tmpbuf2 = tmpbuf2->next();
+ }
+
+ // now remove all out of the buffer which is NOT allowed in the
+ // new environment and set also another font if that is required
+ tmpbuf = buf;
+ while(tmpbuf) {
+ for(pos_type i = 0; i < tmpbuf->size(); ++i) {
+ if (tmpbuf->getChar(i) == Paragraph::META_INSET) {
+ if (!(*par)->insetAllowed(tmpbuf->getInset(i)->lyxCode()))
+ {
+ tmpbuf->erase(i--);
+ }
+ } else {
+ LyXFont f1 = tmpbuf->getFont(current_view->buffer()->params,i);
+ LyXFont f2 = f1;
+ if (!(*par)->checkInsertChar(f1)) {
+ tmpbuf->erase(i--);
+ } else if (f1 != f2) {
+ tmpbuf->setFont(i, f1);
+ }
+ }
+ }
+ // set the inset owner of this paragraph
+ tmpbuf->setInsetOwner((*par)->inInset());
+ tmpbuf = tmpbuf->next();
+ }
+
+ // make sure there is no class difference
+ SwitchLayoutsBetweenClasses(textclass, tc, buf,
+ current_view->buffer()->params);
+
+ // make the buf exactly the same layout than
+ // the cursor paragraph
+ buf->makeSameLayout(*par);
+
+ // find the end of the buffer
+ Paragraph * lastbuffer = buf;
+ while (lastbuffer->next())
+ lastbuffer = lastbuffer->next();
+
+ bool paste_the_end = false;
+
+ // open the paragraph for inserting the buf
+ // if necessary
+ if (((*par)->size() > pos) || !(*par)->next()) {
+ (*par)->breakParagraphConservative(current_view->buffer()->params,
+ pos);
+ paste_the_end = true;
+ }
+ // set the end for redoing later
+ *endpar = (*par)->next()->next();
+
+ // paste it!
+ lastbuffer->next((*par)->next());
+ (*par)->next()->previous(lastbuffer);
+
+ (*par)->next(buf);
+ buf->previous(*par);
+
+ if ((*par)->next() == lastbuffer)
+ lastbuffer = *par;
+
+ (*par)->pasteParagraph(current_view->buffer()->params);
+ // store the new cursor position
+ *par = lastbuffer;
+ pos = lastbuffer->size();
+ // maybe some pasting
+ if (lastbuffer->next() && paste_the_end) {
+ if (lastbuffer->next()->hasSameLayout(lastbuffer)) {
+ lastbuffer->pasteParagraph(current_view->buffer()->params);
+ } else if (!lastbuffer->next()->size()) {
+ lastbuffer->next()->makeSameLayout(lastbuffer);
+ lastbuffer->pasteParagraph(current_view->buffer()->params);
+ } else if (!lastbuffer->size()) {
+ lastbuffer->makeSameLayout(lastbuffer->next());
+ lastbuffer->pasteParagraph(current_view->buffer()->params);
+ } else
+ lastbuffer->next()->stripLeadingSpaces(tc);
+ }
+ // restore the simple cut buffer
+ buf = simple_cut_clone;