This an update rationalization: do not call update on the insets, but return
the update flag in the dispatch result (I've had to put some default update
value to true in dispatchresult.h, Lars please have a look. If that is no
good, then I'll need a DispatchResult(false, FINISHED_RIGHT, update) for
putting update = true). Only collapsables/insettext handled here (tables
are still unoperational).

For doing this, I've added an LCursor::updatePos to update the cached y
position of the inset. Both the cached y position and this updatePos can be
removed if we switch to absolute document coords.

Still a lot of cleanup to be done, but seems to work reasonably well
already.

The work for making put_selection_at is tricky: we still have the
chicken-and-egg problem (i.e. andre you were right, but not when
scrolling):

if the fitCursor call refers to some point in never-explored-land, then we
don't have y information in insets there, then we cannot even do an update
to get it (because we need the y infomation for setting top_y first). So
this is solved in put_selection_at with:

- setting top_y to the y of the outerPar (that has good info)
- calling update
- calling cursor().updatePos()
- then call fitCursor()

Comments?

Alfredo



Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.459
diff -u -p -u -r1.459 BufferView_pimpl.C
--- BufferView_pimpl.C	11 Nov 2003 09:06:38 -0000	1.459
+++ BufferView_pimpl.C	11 Nov 2003 11:30:14 -0000
@@ -616,8 +616,6 @@ void BufferView::Pimpl::update()
 
 	// check needed to survive LyX startup
 	if (bv_->getLyXText()) {
-		bv_->getLyXText()->redoCursor();
-
 		// update all 'visible' paragraphs
 		ParagraphList::iterator beg;
 		ParagraphList::iterator end;
@@ -625,7 +623,7 @@ void BufferView::Pimpl::update()
 			       top_y(), top_y() + workarea().workHeight(),
 			       beg, end);
 		bv_->text->redoParagraphs(beg, end);
-
+		bv_->getLyXText()->redoCursor();
 		updateScrollbar();
 	}
 	screen().redraw(*bv_);
@@ -962,8 +960,10 @@ bool BufferView::Pimpl::workAreaDispatch
 			cmd2.x -= inset->x();
 			cmd2.y -= inset->y();
 			res = inset->dispatch(cmd2);
-			if (res.update())
+			if (res.update()) {
 				bv_->update();
+				bv_->cursor().updatePos();
+			}
 			res.update(false);
 			switch (res.val()) {
 				case FINISHED:
@@ -973,6 +973,7 @@ bool BufferView::Pimpl::workAreaDispatch
 					theTempCursor.pop();
 					bv_->cursor() = theTempCursor;
 					bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, top_y() + cmd.y);
+					bv_->cursor().updatePos();
 					bv_->fitCursor();
 					return true;
 				default:
@@ -987,12 +988,12 @@ bool BufferView::Pimpl::workAreaDispatch
 			lyxerr << "dispatching " << cmd1
 			       << " to surrounding LyXText "
 			       << bv_->cursor().innerText() << endl;
-			cursor_ = theTempCursor;
+			bv_->cursor() = theTempCursor;
 			theTempCursor.dispatch(cmd1);
+			bv_->update();
+			bv_->cursor().updatePos();
 			//return DispatchResult(true, true);
 		}
-
-		bv_->update();
 		// see workAreaKeyPress
 		cursor_timeout.restart();
 		screen().showCursor(*bv_);
Index: bufferview_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferview_funcs.C,v
retrieving revision 1.124
diff -u -p -u -r1.124 bufferview_funcs.C
--- bufferview_funcs.C	10 Nov 2003 13:23:09 -0000	1.124
+++ bufferview_funcs.C	11 Nov 2003 11:30:15 -0000
@@ -19,6 +19,7 @@
 #include "buffer.h"
 #include "bufferparams.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "gettext.h"
 #include "language.h"
 #include "LColor.h"
@@ -272,8 +273,12 @@ void put_selection_at(BufferView * bv, P
 
 	LyXText * text = par.text(bv);
 	par.lockPath(bv);
-
+	//hack for the chicken and egg problem
+	if (par.inset())
+		bv->top_y(par.outerPar()->y);
+	bv->update();
 	text->setCursor(cur.pit(), cur.pos());
+	bv->cursor().updatePos();
 
 	if (length) {
 		text->setSelectionRange(length);
@@ -281,7 +286,7 @@ void put_selection_at(BufferView * bv, P
 		if (backwards)
 			text->cursor = text->selection.start;
 	}
-	
+
 	bv->fitCursor();
 	bv->update();
 }
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.18
diff -u -p -u -r1.18 cursor.C
--- cursor.C	11 Nov 2003 09:06:40 -0000	1.18
+++ cursor.C	11 Nov 2003 11:30:15 -0000
@@ -113,7 +113,7 @@ void LCursor::push(UpdatableInset * inse
 {
 	lyxerr << "LCursor::push()  inset: " << inset << endl;
 	data_.push_back(CursorItem(inset));
-	cached_y_ = bv_->top_y() + inset->y();
+	cached_y_ = bv_->top_y() + innerInset()->y();
 }
 
 
@@ -154,6 +154,13 @@ LyXText * LCursor::innerText() const
 				return data_[i].text();
 	}
 	return bv_->text;
+}
+
+
+void LCursor::updatePos()
+{
+	if (!data_.empty())
+		cached_y_ = bv_->top_y() + innerInset()->y();
 }
 
 
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.8
diff -u -p -u -r1.8 cursor.h
--- cursor.h	11 Nov 2003 09:06:40 -0000	1.8
+++ cursor.h	11 Nov 2003 11:30:15 -0000
@@ -75,6 +75,8 @@ public:
 	LyXText * innerText() const;
 	/// returns x,y position
 	void getPos(int & x, int & y) const;
+	/// cache the absolute coordinate from the top inset
+	void updatePos();
 	///
 	friend std::ostream & operator<<(std::ostream &, LCursor const &);
 public:
Index: dispatchresult.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/dispatchresult.h,v
retrieving revision 1.9
diff -u -p -u -r1.9 dispatchresult.h
--- dispatchresult.h	10 Nov 2003 14:29:39 -0000	1.9
+++ dispatchresult.h	11 Nov 2003 11:30:15 -0000
@@ -51,9 +51,9 @@ public:
 	DispatchResult(bool dis)
 		: dispatched_(dis), update_(false), val_(NONE) {}
 	DispatchResult(bool dis, bool update)
-		: dispatched_(dis), update_(true), val_(NONE) {}
+		: dispatched_(dis), update_(update), val_(NONE) {}
 	DispatchResult(bool dis, dispatch_result_t val)
-		: dispatched_(dis), update_(false), val_(val) {}
+		: dispatched_(dis), update_(true), val_(val) {}
 	dispatch_result_t val() const { return val_; }
 	void val(dispatch_result_t drt) {
 		val_ = drt;
Index: paragraph_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v
retrieving revision 1.87
diff -u -p -u -r1.87 paragraph_funcs.C
--- paragraph_funcs.C	10 Nov 2003 18:15:53 -0000	1.87
+++ paragraph_funcs.C	11 Nov 2003 11:30:16 -0000
@@ -628,6 +628,6 @@ void getParsInRange(ParagraphList & pl,
 	for (--beg; beg != begpar && beg->y > ystart; --beg)
 		;
 
-	for (end = beg ; end != endpar && end->y < yend; ++end)
+	for (end = beg ; end != endpar && end->y <= yend; ++end)
 		;
 }
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.205
diff -u -p -u -r1.205 insetcollapsable.C
--- insets/insetcollapsable.C	11 Nov 2003 09:06:40 -0000	1.205
+++ insets/insetcollapsable.C	11 Nov 2003 11:30:19 -0000
@@ -205,8 +205,6 @@ DispatchResult InsetCollapsable::lfunMou
 		lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
 		collapsed_ = false;
 		edit(bv, true);
-		bv->buffer()->markDirty();
-		bv->update();
 		return DispatchResult(true, true);
 	}
 
@@ -214,12 +212,9 @@ DispatchResult InsetCollapsable::lfunMou
 		if (!collapsed_) {
 			collapsed_ = true;
 			lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
-			bv->update();
 			return DispatchResult(false, FINISHED_RIGHT);
 		}
 		collapsed_ = false;
-		bv->update();
-		bv->buffer()->markDirty();
 		lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
 	} else if (!collapsed_ && cmd.y > button_dim.y2) {
 		lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
@@ -281,8 +276,6 @@ void InsetCollapsable::edit(BufferView *
 		collapsed_ = false;
 		// set this only here as it should be recollapsed only if
 		// it was already collapsed!
-		bv->update();
-		bv->buffer()->markDirty();
 		inset.edit(bv, x, y);
 	} else {
 		if (y <= button_dim.y2)
@@ -398,7 +391,6 @@ void InsetCollapsable::open(BufferView *
 		return;
 
 	collapsed_ = false;
-	bv->update();
 }
 
 
@@ -408,7 +400,6 @@ void InsetCollapsable::close(BufferView 
 		return;
 
 	collapsed_ = true;
-	bv->update();
 }
 
 
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.538
diff -u -p -u -r1.538 insettext.C
--- insets/insettext.C	11 Nov 2003 09:06:41 -0000	1.538
+++ insets/insettext.C	11 Nov 2003 11:30:21 -0000
@@ -290,7 +290,6 @@ void InsetText::updateLocal(BufferView *
 		text_.selection.cursor = text_.cursor;
 
 //	bv->fitCursor();
-	bv->update();
 	bv->owner()->view_state_changed();
 	bv->owner()->updateMenubar();
 	bv->owner()->updateToolbar();

Reply via email to