]> git.lyx.org Git - features.git/commitdiff
Fix crash that occurs if the cursor is in a table cell when the document class
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 21 May 2006 17:33:03 +0000 (17:33 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 21 May 2006 17:33:03 +0000 (17:33 +0000)
is changed
* src/cursor.C: remove unused 'using std::swap'
* src/BufferView.C: ditto

* src/CutAndPaste.[Ch]
(switchBetweenClasses): replace ParagraphList argument with InsetText
argument. This avoids an unnecessary swap in lyxfunc.C.

* src/CutAndPaste.C
(pasteSelectionHelper): Adjust to the changes above
(pasteSelectionHelper): Use ParagraphList::swap instead of std::swap.
This fixes the crash.

* src/lyxfunc.C
(LyXFunc::dispatch): Adjust to switchBetweenClasses changes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13895 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/CutAndPaste.C
src/CutAndPaste.h
src/cursor.C
src/lyxfunc.C

index 01cfc41d8eef8fbf3e737869f29d0133340a3e2b..cbe6a33ef94acb1eb22a09c23d2499694a77b7cd 100644 (file)
@@ -54,7 +54,6 @@ using lyx::cap::setSelectionRange;
 using std::distance;
 using std::find;
 using std::string;
-using std::swap;
 using std::vector;
 
 
index 1b652813253ddbe8178ade578dec03def613373f..7f7a0e0080e5cf9e6d17d1e9ac9af70da5317f9b 100644 (file)
@@ -150,7 +150,14 @@ pasteSelectionHelper(Buffer const & buffer,
        }
 
        // Make sure there is no class difference.
-       lyx::cap::switchBetweenClasses(textclass, tc, insertion, errorlist);
+       InsetText in;
+       // This works without copying any paragraph data because we have
+       // a specialized swap method for ParagraphList. This is important
+       // since we store pointers to insets at some places and we don't
+       // want to invalidate them.
+       insertion.swap(in.paragraphs());
+       lyx::cap::switchBetweenClasses(textclass, tc, in, errorlist);
+       insertion.swap(in.paragraphs());
 
        ParagraphList::iterator tmpbuf = insertion.begin();
        int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
@@ -200,8 +207,7 @@ pasteSelectionHelper(Buffer const & buffer,
 
        // Prepare the paragraphs and insets for insertion.
        // A couple of insets store buffer references so need updating.
-       InsetText in;
-       std::swap(in.paragraphs(), insertion);
+       insertion.swap(in.paragraphs());
 
        ParIterator fpit = par_iterator_begin(in);
        ParIterator fend = par_iterator_end(in);
@@ -223,7 +229,7 @@ pasteSelectionHelper(Buffer const & buffer,
                        }
                }
        }
-       std::swap(in.paragraphs(), insertion);
+       insertion.swap(in.paragraphs());
 
        // Split the paragraph for inserting the buf if necessary.
        if (!empty)
@@ -368,18 +374,15 @@ string grabAndEraseSelection(LCursor & cur)
 
 
 void switchBetweenClasses(textclass_type c1, textclass_type c2,
-       ParagraphList & pars, ErrorList & errorlist)
+       InsetText & in, ErrorList & errorlist)
 {
-       BOOST_ASSERT(!pars.empty());
+       BOOST_ASSERT(!in.paragraphs().empty());
        if (c1 == c2)
                return;
 
        LyXTextClass const & tclass1 = textclasslist[c1];
        LyXTextClass const & tclass2 = textclasslist[c2];
 
-       InsetText in;
-       std::swap(in.paragraphs(), pars);
-
        // layouts
        ParIterator end = par_iterator_end(in);
        for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
@@ -432,8 +435,6 @@ void switchBetweenClasses(textclass_type c1, textclass_type c2,
                        }
                }
        }
-
-       std::swap(in.paragraphs(), pars);
 }
 
 
index 9c4eeb72b041d3bd9f0c9369aaeb55b610b81764..c92bb3a24ffeb3c156012929ffe7a46c3cfd050a 100644 (file)
@@ -23,6 +23,7 @@
 
 class Buffer;
 class ErrorList;
+class InsetText;
 class LyXTextClass;
 class LCursor;
 
@@ -67,9 +68,8 @@ void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
  *  It changes layouts and character styles.
  */
 void switchBetweenClasses(lyx::textclass_type c1,
-                               lyx::textclass_type c2,
-                               ParagraphList & par,
-                               ErrorList &);
+                          lyx::textclass_type c2,
+                          InsetText & in, ErrorList &);
 
 // only used by the spellchecker
 void replaceWord(LCursor & cur, std::string const & replacestring);
index 4c7b6a9873585a819a65ecdc0659312d742d13b4..a0603328452a98586598dff1ac35714762b88263 100644 (file)
@@ -63,7 +63,6 @@ using std::endl;
 using std::isalpha;
 #endif
 using std::min;
-using std::swap;
 
 namespace {
 
index b690c7300c0910c2d0f38b6dc16af8b4c498ee12..41b04b281eff08f59b46dcb26f5fedb62b0cdba9 100644 (file)
@@ -1563,7 +1563,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        ErrorList el;
                        lyx::cap::switchBetweenClasses(
                                old_class, new_class,
-                               buffer->paragraphs(), el);
+                               static_cast<InsetText &>(buffer->inset()), el);
 
                        view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
                        bufferErrors(*buffer, el);