[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:

| I have now a patch that fixes this.
| 
| I'll post it when the compile finishes.
| IMHO if anything breaks by this, it is only an exposed bug that we hid
| earlier.
| 
| I have not done extensive testing, but loading the UserGuide and
| cursoring throught it seems to work. I have not tested any real
| editing.

I just saw that there are problems with new documents, I'll look at
that shortly.

Here is the patch: (might not apply to a tree since I removed all ws
changes for Angus' benefit)

Please comment. (the patch is not very clean, but it moves uglyness
where it belongs.)

Index: src/lyxrow.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxrow.C,v
retrieving revision 1.18
diff -u -p -r1.18 lyxrow.C
--- src/lyxrow.C	11 Mar 2003 11:52:04 -0000	1.18
+++ src/lyxrow.C	13 Mar 2003 00:10:23 -0000
@@ -159,6 +159,9 @@ namespace {
 
 bool nextRowIsAllInset(Row const & row, pos_type last)
 {
+	if (last + 1 >= row.par()->size())
+		return false;
+
 	if (!row.par()->isInset(last + 1))
 		return false;
 
@@ -192,7 +195,7 @@ int Row::numberOfSeparators() const
 	pos_type p = max(pos(), par()->beginningOfBody());
 
 	int n = 0;
-	for (; p <= last; ++p) {
+	for (; p < last; ++p) {
 		if (par()->isSeparator(p)) {
 			++n;
 		}
@@ -208,7 +211,7 @@ int Row::numberOfHfills() const
 
 	// hfill *DO* count at the beginning of paragraphs!
 	if (first) {
-		while (first <= last && par()->isHfill(first)) {
+		while (first < last && par()->isHfill(first)) {
 			++first;
 		}
 	}
@@ -218,8 +221,8 @@ int Row::numberOfHfills() const
 	int n = 0;
 
 	// last, because the end is ignored!
-	for (pos_type p = first; p <= last; ++p) {
+	for (pos_type p = first; p < last; ++p) {
 		if (par()->isHfill(p))
 			++n;
 	}
Index: src/paragraph_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.C,v
retrieving revision 1.53
diff -u -p -r1.53 paragraph_pimpl.C
--- src/paragraph_pimpl.C	12 Mar 2003 19:16:40 -0000	1.53
+++ src/paragraph_pimpl.C	13 Mar 2003 00:10:24 -0000
@@ -252,12 +252,14 @@ void Paragraph::Pimpl::rejectChange(pos_
 
 Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
 {
-	// This is in the critical path for loading!
-	pos_type const siz = size();
-	lyx::Assert(pos <= siz);
+	//lyx::Assert(pos <= siz);
 	// This is stronger, and I belive that this is the assertion
 	// that we should really use. (Lgb)
-	//Assert(pos < size());
+	lyx::Assert(pos < size());
+
+#if 0
+	// This is in the critical path for loading!
+	pos_type const siz = size();
 
 	// Then this has no meaning. (Lgb)
 	if (!siz || pos == siz) {
@@ -266,7 +268,7 @@ Paragraph::value_type Paragraph::Pimpl::
 			<< "  is a bit silly !" << endl;
 		return '\0';
 	}
-
+#endif
 	return text[pos];
 }
 
Index: src/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.309
diff -u -p -r1.309 text.C
--- src/text.C	12 Mar 2003 23:19:09 -0000	1.309
+++ src/text.C	13 Mar 2003 00:10:26 -0000
@@ -422,10 +422,12 @@ bool LyXText::isBoundary(Buffer const * 
 int LyXText::leftMargin(BufferView * bview, Row const * row) const
 {
 	Inset * ins;
-	if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
-		(ins=row->par()->getInset(row->pos())) &&
-		(ins->needFullRow() || ins->display()))
-		return LEFT_MARGIN;
+
+	if (row->pos() < row->par()->size())
+		if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
+		    (ins = row->par()->getInset(row->pos())) &&
+		    (ins->needFullRow() || ins->display()))
+			return LEFT_MARGIN;
 
 	LyXTextClass const & tclass =
 		bview->buffer()->params.getLyXTextClass();
@@ -615,10 +617,12 @@ int LyXText::leftMargin(BufferView * bvi
 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
 {
 	Inset * ins;
-	if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
-		(ins=row.par()->getInset(row.pos())) &&
-		(ins->needFullRow() || ins->display()))
-		return PAPER_MARGIN;
+
+	if (row.pos() < row.par()->size())
+		if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
+		    (ins=row.par()->getInset(row.pos())) &&
+		    (ins->needFullRow() || ins->display()))
+			return PAPER_MARGIN;
 
 	LyXTextClass const & tclass = buf.params.getLyXTextClass();
 	LyXLayout_ptr const & layout = row.par()->layout();
@@ -722,7 +726,9 @@ LyXText::rowBreakPoint(BufferView & bv, 
 	pos_type const body_pos = par->beginningOfBody();
 	pos_type const last = par->size();
 	pos_type point = last;
-	pos_type i = pos;
+
+	if (pos == last)
+		return last;
 
 	// Now we iterate through until we reach the right margin
 	// or the end of the par, then choose the possible break
@@ -734,8 +740,9 @@ LyXText::rowBreakPoint(BufferView & bv, 
 	// pixel width since last breakpoint
 	int chunkwidth = 0;
 
-	for (i = pos; i < last; ++i) {
+	pos_type i = pos;
+	for (; i < last; ++i) {
 
 		if (par->isNewline(i)) {
 			point = i;
@@ -976,8 +983,8 @@ void LyXText::setHeightOfRow(BufferView 
 	int maxwidth = 0;
 
 	// Check if any insets are larger
-	for (pos_type pos = row->pos(); pos <= pos_end; ++pos) {
+	for (pos_type pos = row->pos(); pos < pos_end; ++pos) {
 		if (row->par()->isInset(pos)) {
 			tmpfont = getFont(bview->buffer(), row->par(), pos);
 			tmpinset = row->par()->getInset(pos);
@@ -1814,9 +1821,10 @@ void LyXText::prepareToPrint(BufferView 
 
 		// center displayed insets
 		Inset * inset;
-		if (row->par()->isInset(row->pos())
-		    && (inset=row->par()->getInset(row->pos()))
+		if (row->pos() < row->par()->size()
+		    && row->par()->isInset(row->pos())
+		    && (inset = row->par()->getInset(row->pos()))
 		    && (inset->display())) // || (inset->scroll() < 0)))
 		    align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
 			? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.286
diff -u -p -r1.286 text2.C
--- src/text2.C	11 Mar 2003 16:38:37 -0000	1.286
+++ src/text2.C	13 Mar 2003 00:10:27 -0000
@@ -1769,8 +1769,9 @@ void LyXText::setCursor(BufferView * bvi
 	Inset * ins;
 	if (row->previous() && pos &&
 		row->previous()->par() == row->par() &&
+	    pos < par->size() &&
 		par->getChar(pos) == Paragraph::META_INSET &&
-		(ins=par->getInset(pos)) && (ins->needFullRow() || ins->display()))
+		(ins = par->getInset(pos)) && (ins->needFullRow() || ins->display()))
 	{
 		row = row->previous();
 		y -= row->height();
@@ -1786,13 +1787,16 @@ void LyXText::setCursor(BufferView * bvi
 
 	// None of these should happen, but we're scaredy-cats
 	if (pos > par->size()) {
+		lyxerr << "dont like 1" << endl;
 		pos = 0;
 		cur.pos(0);
 	} else if (pos > last + 1) {
+		lyxerr << "dont like 2" << endl;
 		// This shouldn't happen.
 		pos = last + 1;
 		cur.pos(pos);
 	} else if (pos < row->pos()) {
+		lyxerr << "dont like 3" << endl;
 		pos = row->pos();
 		cur.pos(pos);
 	}
-- 
        Lgb

Reply via email to