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
This commit is contained in:
Georg Baum 2006-05-21 17:33:03 +00:00
parent 7aeddf0bc3
commit 2392e19c66
5 changed files with 16 additions and 17 deletions

View File

@ -54,7 +54,6 @@ using lyx::cap::setSelectionRange;
using std::distance;
using std::find;
using std::string;
using std::swap;
using std::vector;

View 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);
}

View 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);

View File

@ -63,7 +63,6 @@ using std::endl;
using std::isalpha;
#endif
using std::min;
using std::swap;
namespace {

View 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);