From: Georg Baum Date: Sun, 21 May 2006 17:33:03 +0000 (+0000) Subject: Fix crash that occurs if the cursor is in a table cell when the document class X-Git-Tag: 1.6.10~13205 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2392e19c664a292db0615b410695f451886cbb56;p=features.git Fix crash that occurs if the cursor is in a table cell when the document class 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 --- diff --git a/src/BufferView.C b/src/BufferView.C index 01cfc41d8e..cbe6a33ef9 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -54,7 +54,6 @@ using lyx::cap::setSelectionRange; using std::distance; using std::find; using std::string; -using std::swap; using std::vector; diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 1b65281325..7f7a0e0080 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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); } diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index 9c4eeb72b0..c92bb3a24f 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -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); diff --git a/src/cursor.C b/src/cursor.C index 4c7b6a9873..a060332845 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -63,7 +63,6 @@ using std::endl; using std::isalpha; #endif using std::min; -using std::swap; namespace { diff --git a/src/lyxfunc.C b/src/lyxfunc.C index b690c7300c..41b04b281e 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1563,7 +1563,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) ErrorList el; lyx::cap::switchBetweenClasses( old_class, new_class, - buffer->paragraphs(), el); + static_cast(buffer->inset()), el); view()->setCursor(backcur.asDocIterator(&(buffer->inset()))); bufferErrors(*buffer, el);