since the problem is that cur.pos() can become > cur.lastpos() after the 
removal of newline insets (by setAutoBreakRows), the simplest fix is to set 
the cursor to lastpos in such a case. This is basically a reimplementation of 
cur.normalize(), which is not yet textified and thus couldn't be used 
directly. 
See attached patch.

A somewhat "smarter" solution would try to reset the cursor to its relative 
position from lastpos (by storing that position in advance). By this is 
tricky, since the new lastpos minus the stored relative position of the 
cursor from the old lastpos could as well be < 0.

So I'd propose to do it the easy way. What do you think?

Jürgen
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.487
diff -p -u -r1.487 insettabular.C
--- insets/insettabular.C	15 Sep 2005 10:40:12 -0000	1.487
+++ insets/insettabular.C	15 Sep 2005 17:16:38 -0000
@@ -1417,6 +1417,9 @@ void InsetTabular::tabularFeatures(LCurs
 	case LyXTabular::SET_PWIDTH: {
 		LyXLength const len(value);
 		tabular.setColumnPWidth(cur.idx(), len);
+		// cur position can become invalid after newlines were removed
+		if (cur.pos() > cur.lastpos())
+			cur.pos() = cur.lastpos();
 		if (len.zero()
 		    && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
 			tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
@@ -1425,6 +1428,9 @@ void InsetTabular::tabularFeatures(LCurs
 
 	case LyXTabular::SET_MPWIDTH:
 		tabular.setMColumnPWidth(cur.idx(), LyXLength(value));
+		// cur position can become invalid after newlines were removed
+		if (cur.pos() > cur.lastpos())
+			cur.pos() = cur.lastpos();
 		break;
 
 	case LyXTabular::SET_SPECIAL_COLUMN:

Reply via email to