Fix crash in undo

2004-11-07 Thread Kornelia Pietsch

This fixes a crash in undo when creatin redo information.
Already in CVS.

Andre'
Index: undo.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo.C,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -p -r1.56 -r1.57
--- undo.C  23 Oct 2004 11:04:41 -  1.56
+++ undo.C  5 Nov 2004 06:12:21 -   1.57
@@ -42,28 +42,30 @@ bool undo_finished;
 std::ostream  operator(std::ostream  os, Undo const  undo)
 {
return os   from:   undo.from   end:   undo.end
+ cell:\n  undo.cell
  cursor:\n  undo.cursor;
 }
 
 
 void recordUndo(Undo::undo_kind kind,
-   LCursor  cur, par_type first_par, par_type last_par,
+   DocIterator  cell, 
+   par_type first_par, par_type last_par,
+   DocIterator  cur,
limited_stackUndo  stack)
 {
-   BOOST_ASSERT(first_par = cur.lastpar());
-   BOOST_ASSERT(last_par = cur.lastpar());
-
if (first_par  last_par)
std::swap(first_par, last_par);
 
// create the position information of the Undo entry
Undo undo;
undo.kind = kind;
-   undo.cursor = StableDocIterator(cur);
+   undo.cell = cell;
+   undo.cursor = cur;
lyxerr  recordUndo: cur:   cur  endl;
-   lyxerr  recordUndo: undo.cursor:   undo.cursor  endl;
+   lyxerr  recordUndo: pos:   cur.pos()  endl;
+   //lyxerr  recordUndo: cell:   cell  endl;
undo.from = first_par;
-   undo.end = cur.lastpar() - last_par;
+   undo.end = cell.lastpar() - last_par;
 
// Undo::ATOMIC are always recorded (no overlapping there).
// As nobody wants all removed character appear one by one when undoing,
@@ -71,21 +73,21 @@ void recordUndo(Undo::undo_kind kind,
if (!undo_finished
 kind != Undo::ATOMIC
 !stack.empty()
-stack.top().cursor.size() == undo.cursor.size()
+stack.top().cell.size() == undo.cell.size()
   stack.top().kind == undo.kind
   stack.top().from == undo.from
   stack.top().end == undo.end)
return;
 
// fill in the real data to be saved
-   if (cur.inMathed()) {
+   if (cell.inMathed()) {
// simply use the whole cell
-   undo.array = asString(cur.cell());
+   undo.array = asString(cell.cell());
} else {
// some more effort needed here as 'the whole cell' of the
// main LyXText _is_ the whole document.
// record the relevant paragraphs
-   LyXText * text = cur.text();
+   LyXText * text = cell.text();
BOOST_ASSERT(text);
ParagraphList  plist = text-paragraphs();
ParagraphList::iterator first = plist.begin();
@@ -103,22 +105,29 @@ void recordUndo(Undo::undo_kind kind,
undo_finished = false;
 }
 
+void recordUndo(Undo::undo_kind kind,
+   LCursor  cur, par_type first_par, par_type last_par,
+   limited_stackUndo  stack)
+{
+   BOOST_ASSERT(first_par = cur.lastpar());
+   BOOST_ASSERT(last_par = cur.lastpar());
+
+   recordUndo(kind, cur, first_par, last_par, cur, stack);
+}
+
 
 void performUndoOrRedo(BufferView  bv, Undo const  undo)
 {
-   LCursor  cur = bv.cursor();
-   lyxerr  undo, performing:   undo  std::endl;
-   cur.setCursor(undo.cursor.asDocIterator(bv.buffer()-inset()));
-   cur.selection() = false;
-
-   if (cur.inMathed()) {
+   //lyxerr  undo, performing:   undo  std::endl;
+   DocIterator dit = undo.cell.asDocIterator(bv.buffer()-inset());
+   if (dit.inMathed()) {
// We stored the full cell here as there is not much to be
// gained by storing just 'a few' paragraphs (most if not
// all math inset cells have just one paragraph!)
-   asArray(undo.array, cur.cell());
+   asArray(undo.array, dit.cell());
} else {
// Some finer machinery is needed here.
-   LyXText * text = cur.text();
+   LyXText * text = dit.text();
BOOST_ASSERT(text);
ParagraphList  plist = text-paragraphs();
 
@@ -135,6 +144,9 @@ void performUndoOrRedo(BufferView  bv, 
plist.insert(first, undo.pars.begin(), undo.pars.end());
}
 
+   LCursor  cur = bv.cursor();
+   cur.setCursor(undo.cursor.asDocIterator(bv.buffer()-inset()));
+   cur.selection() = false;
cur.resetAnchor();
finishUndo();
 }
@@ -150,40 +162,52 @@ bool textUndoOrRedo(BufferView  bv,
return false;
}
 
+   //
+   // Adjust undo stack and get hold of current undo data.
+   //
Undo undo = stack.top();
stack.pop();
finishUndo();
 
-   // This implements redo
-   otherstack.push(undo);
-   // FIXME

Fix crash in undo

2004-11-07 Thread Kornelia Pietsch

This fixes a crash in undo when creatin redo information.
Already in CVS.

Andre'
Index: undo.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo.C,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -p -r1.56 -r1.57
--- undo.C  23 Oct 2004 11:04:41 -  1.56
+++ undo.C  5 Nov 2004 06:12:21 -   1.57
@@ -42,28 +42,30 @@ bool undo_finished;
 std::ostream & operator<<(std::ostream & os, Undo const & undo)
 {
return os << " from: " << undo.from << " end: " << undo.end
+   << " cell:\n" << undo.cell
<< " cursor:\n" << undo.cursor;
 }
 
 
 void recordUndo(Undo::undo_kind kind,
-   LCursor & cur, par_type first_par, par_type last_par,
+   DocIterator & cell, 
+   par_type first_par, par_type last_par,
+   DocIterator & cur,
limited_stack & stack)
 {
-   BOOST_ASSERT(first_par <= cur.lastpar());
-   BOOST_ASSERT(last_par <= cur.lastpar());
-
if (first_par > last_par)
std::swap(first_par, last_par);
 
// create the position information of the Undo entry
Undo undo;
undo.kind = kind;
-   undo.cursor = StableDocIterator(cur);
+   undo.cell = cell;
+   undo.cursor = cur;
lyxerr << "recordUndo: cur: " << cur << endl;
-   lyxerr << "recordUndo: undo.cursor: " << undo.cursor << endl;
+   lyxerr << "recordUndo: pos: " << cur.pos() << endl;
+   //lyxerr << "recordUndo: cell: " << cell << endl;
undo.from = first_par;
-   undo.end = cur.lastpar() - last_par;
+   undo.end = cell.lastpar() - last_par;
 
// Undo::ATOMIC are always recorded (no overlapping there).
// As nobody wants all removed character appear one by one when undoing,
@@ -71,21 +73,21 @@ void recordUndo(Undo::undo_kind kind,
if (!undo_finished
&& kind != Undo::ATOMIC
&& !stack.empty()
-   && stack.top().cursor.size() == undo.cursor.size()
+   && stack.top().cell.size() == undo.cell.size()
  && stack.top().kind == undo.kind
  && stack.top().from == undo.from
  && stack.top().end == undo.end)
return;
 
// fill in the real data to be saved
-   if (cur.inMathed()) {
+   if (cell.inMathed()) {
// simply use the whole cell
-   undo.array = asString(cur.cell());
+   undo.array = asString(cell.cell());
} else {
// some more effort needed here as 'the whole cell' of the
// main LyXText _is_ the whole document.
// record the relevant paragraphs
-   LyXText * text = cur.text();
+   LyXText * text = cell.text();
BOOST_ASSERT(text);
ParagraphList & plist = text->paragraphs();
ParagraphList::iterator first = plist.begin();
@@ -103,22 +105,29 @@ void recordUndo(Undo::undo_kind kind,
undo_finished = false;
 }
 
+void recordUndo(Undo::undo_kind kind,
+   LCursor & cur, par_type first_par, par_type last_par,
+   limited_stack & stack)
+{
+   BOOST_ASSERT(first_par <= cur.lastpar());
+   BOOST_ASSERT(last_par <= cur.lastpar());
+
+   recordUndo(kind, cur, first_par, last_par, cur, stack);
+}
+
 
 void performUndoOrRedo(BufferView & bv, Undo const & undo)
 {
-   LCursor & cur = bv.cursor();
-   lyxerr << "undo, performing: " << undo << std::endl;
-   cur.setCursor(undo.cursor.asDocIterator(()->inset()));
-   cur.selection() = false;
-
-   if (cur.inMathed()) {
+   //lyxerr << "undo, performing: " << undo << std::endl;
+   DocIterator dit = undo.cell.asDocIterator(()->inset());
+   if (dit.inMathed()) {
// We stored the full cell here as there is not much to be
// gained by storing just 'a few' paragraphs (most if not
// all math inset cells have just one paragraph!)
-   asArray(undo.array, cur.cell());
+   asArray(undo.array, dit.cell());
} else {
// Some finer machinery is needed here.
-   LyXText * text = cur.text();
+   LyXText * text = dit.text();
BOOST_ASSERT(text);
ParagraphList & plist = text->paragraphs();
 
@@ -135,6 +144,9 @@ void performUndoOrRedo(BufferView & bv, 
plist.insert(first, undo.pars.begin(), undo.pars.end());
}
 
+   LCursor & cur = bv.cursor()

Re: Crash with undo

2002-10-29 Thread Jean-Marc Lasgouttes
 Dekel == Dekel Tsur [EMAIL PROTECTED] writes:

Dekel On Sat, Oct 26, 2002 at 12:23:51AM +0200, Dekel Tsur wrote:
 Open the attached file. Press delete 3 times, and then press undo
 twice, and LyX will crash. Also, after one undo, the display on
 screen is incorrect (only the c is shown, while the DVI output both
 the 'b' and 'c' are shown). The same crash also happen in 1.2.2cvs

Dekel And the file is here.

Isn't this bug #681?

JMarc



Re: Crash with undo

2002-10-29 Thread Dekel Tsur
On Tue, Oct 29, 2002 at 02:01:12PM +0100, Jean-Marc Lasgouttes wrote:
  Dekel == Dekel Tsur [EMAIL PROTECTED] writes:
 
 Dekel On Sat, Oct 26, 2002 at 12:23:51AM +0200, Dekel Tsur wrote:
  Open the attached file. Press delete 3 times, and then press undo
  twice, and LyX will crash. Also, after one undo, the display on
  screen is incorrect (only the c is shown, while the DVI output both
  the 'b' and 'c' are shown). The same crash also happen in 1.2.2cvs
 
 Dekel And the file is here.
 
 Isn't this bug #681?

It is possible.



Re: Crash with undo

2002-10-29 Thread Jean-Marc Lasgouttes
> "Dekel" == Dekel Tsur <[EMAIL PROTECTED]> writes:

Dekel> On Sat, Oct 26, 2002 at 12:23:51AM +0200, Dekel Tsur wrote:
>> Open the attached file. Press delete 3 times, and then press undo
>> twice, and LyX will crash. Also, after one undo, the display on
>> screen is incorrect (only the c is shown, while the DVI output both
>> the 'b' and 'c' are shown). The same crash also happen in 1.2.2cvs

Dekel> And the file is here.

Isn't this bug #681?

JMarc



Re: Crash with undo

2002-10-29 Thread Dekel Tsur
On Tue, Oct 29, 2002 at 02:01:12PM +0100, Jean-Marc Lasgouttes wrote:
> > "Dekel" == Dekel Tsur <[EMAIL PROTECTED]> writes:
> 
> Dekel> On Sat, Oct 26, 2002 at 12:23:51AM +0200, Dekel Tsur wrote:
> >> Open the attached file. Press delete 3 times, and then press undo
> >> twice, and LyX will crash. Also, after one undo, the display on
> >> screen is incorrect (only the c is shown, while the DVI output both
> >> the 'b' and 'c' are shown). The same crash also happen in 1.2.2cvs
> 
> Dekel> And the file is here.
> 
> Isn't this bug #681?

It is possible.



Re: Crash with undo

2002-10-28 Thread Jean-Marc Lasgouttes
 Dekel == Dekel Tsur [EMAIL PROTECTED] writes:

Dekel Open the attached file. Press delete 3 times, and then press
Dekel undo twice, and LyX will crash. Also, after one undo, the
Dekel display on screen is incorrect (only the c is shown, while the
Dekel DVI output both the 'b' and 'c' are shown). The same crash also
Dekel happen in 1.2.2cvs

Isn't this bug #681? I think it is a consequence of Juergen's patch to
other undo problems.

JMarc



Re: Crash with undo

2002-10-28 Thread Jean-Marc Lasgouttes
> "Dekel" == Dekel Tsur <[EMAIL PROTECTED]> writes:

Dekel> Open the attached file. Press delete 3 times, and then press
Dekel> undo twice, and LyX will crash. Also, after one undo, the
Dekel> display on screen is incorrect (only the c is shown, while the
Dekel> DVI output both the 'b' and 'c' are shown). The same crash also
Dekel> happen in 1.2.2cvs

Isn't this bug #681? I think it is a consequence of Juergen's patch to
other undo problems.

JMarc



Re: Crash with undo

2002-10-26 Thread Dekel Tsur
On Sat, Oct 26, 2002 at 12:23:51AM +0200, Dekel Tsur wrote:
 Open the attached file. Press delete 3 times, and then press undo twice, 
 and LyX will crash.
 Also, after one undo, the display on screen is incorrect (only the c is shown,
 while the DVI output both the 'b' and 'c' are shown).
 The same crash also happen in 1.2.2cvs

And the file is here.

#LyX 1.2 created this file. For more info see http://www.lyx.org/
\lyxformat 220
\textclass article
\language english
\inputencoding auto
\fontscheme default
\graphics default
\paperfontsize default
\papersize Default
\paperpackage a4
\use_geometry 0
\use_amsmath 0
\use_natbib 0
\use_numerical_citations 0
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default

\layout Standard

a
\layout Standard

b
\layout Standard

c
\the_end



Re: Crash with undo

2002-10-26 Thread Dekel Tsur
On Sat, Oct 26, 2002 at 12:23:51AM +0200, Dekel Tsur wrote:
> Open the attached file. Press delete 3 times, and then press undo twice, 
> and LyX will crash.
> Also, after one undo, the display on screen is incorrect (only the c is shown,
> while the DVI output both the 'b' and 'c' are shown).
> The same crash also happen in 1.2.2cvs

And the file is here.

#LyX 1.2 created this file. For more info see http://www.lyx.org/
\lyxformat 220
\textclass article
\language english
\inputencoding auto
\fontscheme default
\graphics default
\paperfontsize default
\papersize Default
\paperpackage a4
\use_geometry 0
\use_amsmath 0
\use_natbib 0
\use_numerical_citations 0
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default

\layout Standard

a
\layout Standard

b
\layout Standard

c
\the_end



Crash with undo

2002-10-25 Thread Dekel Tsur
Open the attached file. Press delete 3 times, and then press undo twice, 
and LyX will crash.
Also, after one undo, the display on screen is incorrect (only the c is shown,
while the DVI output both the 'b' and 'c' are shown).
The same crash also happen in 1.2.2cvs



Crash with undo

2002-10-25 Thread Dekel Tsur
Open the attached file. Press delete 3 times, and then press undo twice, 
and LyX will crash.
Also, after one undo, the display on screen is incorrect (only the c is shown,
while the DVI output both the 'b' and 'c' are shown).
The same crash also happen in 1.2.2cvs