Lars Gullik Bjønnes wrote:

> I'll apply it before anyne else finds more errors. :-)

Oops, I had:

aaaaa
bbbbb

and make a selection that spans the two rows (for instance the last a and
first b) and cut: crash

The problem is that my previous solution for prevrit is not good enough if
for instance all rows get eliminated (I've put prevrit = rows().begin(),
but that's wrong --that one can be even also eliminated--, what we need is
rows.begin() but when all insertions are done)

So I've solved it in a somewhat ugly way by adding a flag that tells if
prevrit is pointing to a valid position or else we will need to take
rows().begin(). Maybe you can rewrite it in a less ugly way... 

To compensate the uglyness, I took the liberty of rewriting a Very Ugly (C)
loop.

Regards, Alfredo
Index: ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v
retrieving revision 1.1180
diff -u -p -u -r1.1180 ChangeLog
--- ChangeLog	2003/04/01 00:01:41	1.1180
+++ ChangeLog	2003/04/01 08:13:44
@@ -1,3 +1,8 @@
+2003-04-01  Alfredo Braunstein  <[EMAIL PROTECTED]>
+
+	* text2.C (redoParagraphs): fix a bug (introduced by myself) and
+	rewrite a loop
+
 2003-04-01  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
 
 	* text2.C (redoParagraphs): rewrite (with help from Alfredo) for
Index: text2.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/text2.C,v
retrieving revision 1.314
diff -u -p -u -r1.314 text2.C
--- text2.C	2003/04/01 00:01:41	1.314
+++ text2.C	2003/04/01 08:13:47
@@ -683,7 +683,7 @@ void LyXText::redoParagraphs(LyXCursor c
 
 	int y = cur.y() - tmprit->baseline();
 
-	Paragraph * first_phys_par = 0;
+	Paragraph * first_phys_par;
 	if (tmprit == rows().begin()) {
 		// a trick/hack for UNDO
 		// This is needed because in an UNDO/REDO we could have changed
@@ -701,34 +701,21 @@ void LyXText::redoParagraphs(LyXCursor c
 	}
 
 	RowList::iterator prevrit;
+	bool good_prevrit = false;
 	if (tmprit != rows().begin()) {
 		prevrit = boost::prior(tmprit);
-	} else {
-		prevrit = tmprit;
-		y = prevrit ->height();
-	}
+		good_prevrit = true;
+ 	} 
 
 	// remove it
-	Paragraph * tmppar = 0;
-	if (boost::next(tmprit) != rows().end())
-		tmppar = boost::next(tmprit)->par();
-	while (boost::next(tmprit) != rows().end() && tmppar != endpar) {
-		removeRow(boost::next(tmprit));
-		if (boost::next(tmprit) != rows().end()) {
-			tmppar = boost::next(tmprit)->par();
-		} else {
-			tmppar = 0;
-		}
+	while (tmprit != rows().end() && tmprit->par() != endpar) {
+		RowList::iterator tmprit2 = tmprit++; 
+		removeRow(tmprit2);
 	}
 
-	// remove the first one
-	RowList::iterator tmprit2 = tmprit; /* this is because tmprow->previous()
-				 can be 0 */
-	++tmprit;
-	removeRow(tmprit2);
 
 	// Reinsert the paragraphs.
-	tmppar = first_phys_par;
+	Paragraph * tmppar = first_phys_par;
 	do {
 		if (tmppar) {
 			insertParagraph(tmppar, tmprit);
@@ -739,12 +726,16 @@ void LyXText::redoParagraphs(LyXCursor c
 			tmppar = tmppar->next();
 		}
 	} while (tmppar && tmppar != endpar);
-
-	setHeightOfRow(prevrit);
-	const_cast<LyXText *>(this)->postPaint(y - prevrit->height());
 
-	if (tmprit != rows().end() && boost::next(tmprit) != rows().end())
-		setHeightOfRow(boost::next(tmprit));
+	if (good_prevrit) {
+		setHeightOfRow(prevrit);
+		const_cast<LyXText *>(this)->postPaint(y - prevrit->height());
+	} else {
+		setHeightOfRow(rows().begin());
+		const_cast<LyXText *>(this)->postPaint(0);
+	}
+	if (tmprit != rows().end())
+		setHeightOfRow(tmprit);
 	updateCounters();
 }

Reply via email to