- }
- }
- 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(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();
-
- // store the new cursor position
- tmppar = lastbuffer;
- tmppos = lastbuffer->Last();
-
- // maybe some pasting
- if (lastbuffer->Next() && paste_the_end) {
- if (lastbuffer->Next()->HasSameLayout(lastbuffer)) {
- lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
- } else if (!lastbuffer->Next()->Last()) {
- lastbuffer->Next()->MakeSameLayout(lastbuffer);
- lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
- } else if (!lastbuffer->Last()) {
- lastbuffer->MakeSameLayout(lastbuffer->next);
- lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
- } else
- lastbuffer->Next()->ClearParagraph();
+
+ // 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;
+ int depth_delta = (*par)->params().depth() - tmpbuf->params().depth();
+ // temporary set *par as previous of tmpbuf as we might have to realize
+ // the font.
+ tmpbuf->previous(*par);
+
+ // make sure there is no class difference
+ SwitchLayoutsBetweenClasses(textclass, tc, tmpbuf,
+ current_view->buffer()->params);
+
+ Paragraph::depth_type max_depth = (*par)->getMaxDepthAfter(current_view->buffer());
+
+ while(tmpbuf) {
+ // if we have a negative jump so that the depth would go below
+ // 0 depth then we have to redo the delta to this new max depth
+ // level so that subsequent paragraphs are aligned correctly to
+ // this paragraph at level 0.
+ if ((static_cast<int>(tmpbuf->params().depth()) + depth_delta) < 0)
+ depth_delta = 0;
+ // set the right depth so that we are not too deep or shallow.
+ tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
+ if (tmpbuf->params().depth() > max_depth)
+ tmpbuf->params().depth(max_depth);
+ // only set this from the 2nd on as the 2nd depends for maxDepth
+ // still on *par
+ if (tmpbuf->previous() != (*par))
+ max_depth = tmpbuf->getMaxDepthAfter(current_view->buffer());
+ // set the inset owner of this paragraph
+ tmpbuf->setInsetOwner((*par)->inInset());
+ 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);
+ }
+ }
+ }
+ tmpbuf = tmpbuf->next();
+ }
+ // now reset it to 0
+ buf->previous(0);
+
+ // 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;