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/branches/BRANCH_1_4_X@13903 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-05-22 10:12:09 +00:00
parent aa2522a21c
commit 4c0a7b6a0f
6 changed files with 21 additions and 20 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)
@ -367,19 +373,16 @@ string grabAndEraseSelection(LCursor & cur)
}
void SwitchBetweenClasses(textclass_type c1, textclass_type c2,
ParagraphList & pars, ErrorList & errorlist)
void switchBetweenClasses(textclass_type c1, textclass_type c2,
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;
@ -66,10 +67,9 @@ void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
* for a list of paragraphs beginning with the specified par.
* It changes layouts and character styles.
*/
void SwitchBetweenClasses(lyx::textclass_type c1,
lyx::textclass_type c2,
ParagraphList & par,
ErrorList &);
void switchBetweenClasses(lyx::textclass_type c1,
lyx::textclass_type c2,
InsetText & in, ErrorList &);
// only used by the spellchecker
void replaceWord(LCursor & cur, std::string const & replacestring);

View File

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

View File

@ -1547,9 +1547,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
buffer->params().textclass = new_class;
StableDocIterator backcur(view()->cursor());
ErrorList el;
lyx::cap::SwitchBetweenClasses(
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);

View File

@ -103,6 +103,8 @@ What's new
- Fix display of horizontal fill which appears at the end of a line
(bug 2508).
- Fix crash when changing document class while the cursor is inside a table
* Configuration/Installation:
- Replace the old sh version of lib/configure with the new python version