On Fri, 2005-10-07 at 11:43 +0200, Jean-Marc Lasgouttes wrote:
> >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> Martin> Note BTW that not only does cursor up do the same thing, but
> Martin> pressing page up/down in an empty paragraph (_without_ any
> Martin> inset, without any noindent, irrespective of empty par
> Martin> history) will crash lyx:
> 
> This is another problem. It happens because dEPM removes a paragraph
> from paragraph list, without updating the coordcache. Here are first
> the solutions that ought to work but I did not try:
> 
> * In getPitNearY, it is the following test that crashes:
> 
>               if (it->first >= pit && int(it->second.y_) - 
> int(pars_[it->first].ascent()) <= y) {
>                       pit = it->first;
>                       yy = it->second.y_;
>               }
> 
> Obvious solution is to test that it->first < pars_.size(). It solves
> the crash, but other similar ones may happen elsewhere.
> 
> * dEPM could remove a paragraph from the coordcache when it erases it.
>   Requires using startUpdating, though.
> 
> Note that these two solutions mean that we use wrong values for
> coordcache, but we probably do not care.
> 
> 
> The solution I propose (which is the first one I thought about) is
> attached. Basically, we do an update before calling cursorDown. I
> would have preferred a simple metrics(), but this is not available
> ouside of BufferView::Pimpl (should I make it available?). The same
> should be done for page up.
> 
> Thoughts? I'd really appreciate comments on that, since I do not
> understand this code very well.

You're in good company. But your patch works... for page down.
Apparently it should be extended for cursorPrevious ;-)

Improved patch attached.

- Martin

Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.327
diff -u -p -r1.327 lyxtext.h
--- lyxtext.h	20 Sep 2005 08:31:34 -0000	1.327
+++ lyxtext.h	7 Oct 2005 13:16:13 -0000
@@ -176,8 +176,8 @@ public:
 	void recUndo(pit_type first, pit_type last) const;
 	///
 	void recUndo(pit_type first) const;
-	///
-	void setCursorFromCoordinates(LCursor & cur, int x, int y);
+	/// returns true if par was empty and was removed
+	bool setCursorFromCoordinates(LCursor & cur, int x, int y);
 	///
 	InsetBase * editXY(LCursor & cur, int x, int y);
 	/// Move cursor one line up.
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.310
diff -u -p -r1.310 text3.C
--- text3.C	7 Oct 2005 12:00:40 -0000	1.310
+++ text3.C	7 Oct 2005 13:16:15 -0000
@@ -190,8 +190,10 @@ bool LyXText::cursorPrevious(LCursor & c
 
 	int x = cur.x_target();
 
-	setCursorFromCoordinates(cur, x, 0);
-	bool updated = cursorUp(cur);
+	bool updated = setCursorFromCoordinates(cur, x, 0);
+	if (updated)
+	    cur.bv().update();
+	updated |= cursorUp(cur);
 
 	if (cpar == cur.pit() && cpos == cur.pos()) {
 		// we have a row which is taller than the workarea. The
@@ -211,8 +213,10 @@ bool LyXText::cursorNext(LCursor & cur)
 	lyx::pit_type cpar = cur.pit();
 
 	int x = cur.x_target();
-	setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
-	bool updated = cursorDown(cur);
+	bool updated = setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
+	if (updated)
+		cur.bv().update();
+	updated |= cursorDown(cur);
 
 	if (cpar == cur.pit() && cpos == cur.pos()) {
 		// we have a row which is taller than the workarea. The
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.630
diff -u -p -r1.630 text.C
--- text.C	3 Oct 2005 12:13:58 -0000	1.630
+++ text.C	7 Oct 2005 13:16:16 -0000
@@ -2314,7 +2314,7 @@ pos_type LyXText::x2pos(pit_type pit, in
 
 // x,y are screen coordinates
 // sets cursor only within this LyXText
-void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
+bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
 {
 	pit_type pit = getPitNearY(y);
 	int yy = theCoords.get(this, pit).y_ - pars_[pit].ascent();
@@ -2353,5 +2353,5 @@ void LyXText::setCursorFromCoordinates(L
                 << " pos: " << pos
                 << endl;
         
-	setCursor(cur, pit, pos, true, bound);
+	return setCursor(cur, pit, pos, true, bound);
 }

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to