]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.C
redraw fix 1.
[lyx.git] / src / CutAndPaste.C
index 4fd63631557655ed072922df7af4c5acb5ebd250..9d72add1a89a2246fed8b2e8d421069657c70351 100644 (file)
@@ -137,12 +137,12 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
                if (realcut) {
                        buf->params().clear();
                        buf->bibkey = 0;
-                       buf->layout(textclasslist[current_view->buffer()->params.textclass].defaultLayoutName());
+                       buf->layout(textclasslist[current_view->buffer()->params.textclass].defaultLayout());
                }
 
                // paste the paragraphs again, if possible
                if (doclear)
-                       startpar->next()->stripLeadingSpaces(textclass);
+                       startpar->next()->stripLeadingSpaces();
                if (startpar->hasSameLayout(startpar->next()) ||
                    !startpar->next()->size()) {
                        startpar->pasteParagraph(current_view->buffer()->params);
@@ -283,7 +283,13 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                // temporary set *par as previous of tmpbuf as we might have to realize
                // the font.
                tmpbuf->previous(*par);
-               Paragraph::depth_type max_depth = (*par)->getMaxDepthAfter(current_view->buffer());
+
+               // make sure there is no class difference
+               SwitchLayoutsBetweenClasses(textclass, tc, tmpbuf,
+                                           current_view->buffer()->params);
+
+               Paragraph::depth_type max_depth = (*par)->getMaxDepthAfter();
+
                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
@@ -298,7 +304,7 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                        // 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());
+                               max_depth = tmpbuf->getMaxDepthAfter();
                        // set the inset owner of this paragraph
                        tmpbuf->setInsetOwner((*par)->inInset());
                        for(pos_type i = 0; i < tmpbuf->size(); ++i) {
@@ -322,10 +328,6 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                // now reset it to 0
                buf->previous(0);
 
-               // 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);
@@ -372,7 +374,7 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                                lastbuffer->makeSameLayout(lastbuffer->next());
                                lastbuffer->pasteParagraph(current_view->buffer()->params);
                        } else
-                               lastbuffer->next()->stripLeadingSpaces(tc);
+                               lastbuffer->next()->stripLeadingSpaces();
                }
                // restore the simple cut buffer
                buf = simple_cut_clone;
@@ -400,34 +402,28 @@ int CutAndPaste::nrOfParagraphs()
 int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
                                             textclass_type c2,
                                             Paragraph * par,
-                                            BufferParams const & bparams)
+                                            BufferParams const & /*bparams*/)
 {
        int ret = 0;
        if (!par || c1 == c2)
                return ret;
 
+       LyXTextClass const & tclass1 = textclasslist[c1];
+       LyXTextClass const & tclass2 = textclasslist[c2];
        ParIterator end = ParIterator();
        for (ParIterator it = ParIterator(par); it != end; ++it) {
                par = *it;
-               string const name = par->layout();
-               LyXTextClass const & tclass = textclasslist[c2];
-
-               bool hasLayout = tclass.hasLayout(name);
+               string const name = par->layout()->name();
+               bool hasLayout = tclass2.hasLayout(name);
 
-               string lay = tclass.defaultLayoutName();
-               if (hasLayout) {
-                       lay = name;
-               } else {
-                       // not found: use default layout
-                       lay = tclass.defaultLayoutName();
-               }
-               par->layout(lay);
+               if (!hasLayout)
+                       par->layout(tclass2.defaultLayout());
 
-               if (name != par->layout()) {
+               if (!hasLayout && name != tclass1.defaultLayoutName()) {
                        ++ret;
                        string const s = _("Layout had to be changed from\n")
                                + name + _(" to ")
-                               + par->layout()
+                               + par->layout()->name()
                                + _("\nbecause of class conversion from\n")
                                + textclasslist[c1].name() + _(" to ")
                                + textclasslist[c2].name();