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

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

Update: this allows creating new docs as well. It is now close to
something I'd like to apply. 

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:50:31 -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:50:32 -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/rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.4
diff -u -p -r1.4 rowpainter.C
--- src/rowpainter.C	12 Mar 2003 19:16:40 -0000	1.4
+++ src/rowpainter.C	13 Mar 2003 00:50:33 -0000
@@ -312,7 +312,8 @@ bool RowPainter::paintBackground()
 	Inset const * inset = 0;
 
 	if (!bv_.screen().forceClear() && last == row_.pos()
-		&& par_.isInset(row_.pos())) {
+	    && row_.pos() < par_.size()
+	    && par_.isInset(row_.pos())) {
 		inset = par_.getInset(row_.pos());
 		clear_area = inset->doClearArea();
 	}
@@ -897,6 +898,11 @@ bool RowPainter::paintText()
 		if (x_ > bv_.workWidth())
 			break;
 		pos_type pos = text_.vis2log(vpos);
+
+		if (pos >= par_.size()) {
+			++vpos;
+			continue;
+		}
 
 		if (x_ + singleWidth(pos) < 0) {
 			x_ += singleWidth(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:50:34 -0000
@@ -206,6 +206,9 @@ unsigned char LyXText::transformChar(uns
 int LyXText::singleWidth(BufferView * bview, Paragraph * par,
 			 pos_type pos) const
 {
+	if (pos >= par->size())
+		return 0;
+
 	char const c = par->getChar(pos);
 	return singleWidth(bview, par, pos, c);
 }
@@ -214,6 +217,9 @@ int LyXText::singleWidth(BufferView * bv
 int LyXText::singleWidth(BufferView * bview, Paragraph * par,
 			 pos_type pos, char c) const
 {
+	if (pos >= par->size())
+		return 0;
+
 	LyXFont const font = getFont(bview->buffer(), par, pos);
 
 	// The most common case is handled first (Asger)
@@ -422,10 +428,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 +623,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 +732,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 +746,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,7 +989,7 @@ 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);
@@ -1592,10 +1605,11 @@ void LyXText::insertChar(BufferView * bv
 			return;
 		}
 	}
-	
+
 	// the display inset stuff
-	if (cursor.row()->par()->isInset(cursor.row()->pos())) {
+	if (cursor.row()->pos() < cursor.row()->par()->size()
+	    && cursor.row()->par()->isInset(cursor.row()->pos())) {
 		Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
 		if (inset && (inset->display() || inset->needFullRow())) {
 			// force a new break
@@ -1814,9 +1828,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:50:36 -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