+ // 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();
+ }
+
+ // 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
+ 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;