This patch sanitizes fitCursor. 

The main trick is that all y information (but not x) is known after the
first drawing step, and this y information is the only one needed for
fitCursor. So we simply do a redoParagraph on the outer paragraph of the
cursor before asking for it.

Aditionally: 


+ remove some unneeded update calls
+ remove LCursor::cached_y_ and LCursor::updatePos. Not needed nor used
anymore.
+ remove some outdated comments


Alfredo
? ChangeLog-old
? PosIterator.C-save
? PosIterator.h-save
? bfri.C
? safe
? textcursor.C-save
? textcursor.h-save
? insets/insetcollapsable-save.C
? insets/insettext-save.C
? insets/safe
? mathed/safe
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.246
diff -u -p -u -r1.246 BufferView.C
--- BufferView.C	1 Apr 2004 08:58:43 -0000	1.246
+++ BufferView.C	2 Apr 2004 11:40:35 -0000
@@ -379,23 +379,10 @@ void BufferView::setCursor(ParIterator c
 		par[i].inset().edit(cursor(), true);
 
 	cursor().setCursor(makeDocIterator(par, pos), false);
+	par[0].text()->redoParagraph(par[0].par());
 }
 
 
-/*
-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 putSelectionAt with:
-
-- setting top_y to the y of the outerPar (that has good info)
-- calling update
-- calling cursor().updatePos()
-- then call fitCursor()
-
-Ab.
-*/
-
 void BufferView::putSelectionAt(DocIterator const & cur,
 				int length, bool backwards)
 {
@@ -403,15 +390,7 @@ void BufferView::putSelectionAt(DocItera
 
 	cursor().clearSelection();
 
-	LyXText & text = *cur[0].text();
 	setCursor(par, cur.pos());
-	
-	// hack for the chicken and egg problem
-	top_y(text.getPar(par.outerPar()).y);
-
-	update();
-	//text.setCursor(cursor(), cur.par(), cur.pos());
-	cursor().updatePos();
 
 	if (length) {
 		if (backwards) {
@@ -424,7 +403,6 @@ void BufferView::putSelectionAt(DocItera
 	}
 
 	fitCursor();
-	update();
 }
 
 
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.531
diff -u -p -u -r1.531 BufferView_pimpl.C
--- BufferView_pimpl.C	1 Apr 2004 08:58:44 -0000	1.531
+++ BufferView_pimpl.C	2 Apr 2004 11:40:38 -0000
@@ -355,11 +355,14 @@ void BufferView::Pimpl::setBuffer(Buffer
 		lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
 }
 
-
 bool BufferView::Pimpl::fitCursor()
 {
+	// this is enough to get the right y cursor info for fitCursor
+	cursor_.top().text()->redoParagraph(cursor_.top().par());
+
 	if (!screen().fitCursor(bv_))
 		return false;
+
 	updateScrollbar();
 	return true;
 }
@@ -388,7 +391,6 @@ void BufferView::Pimpl::resizeCurrentBuf
 
 	text->init(bv_);
 	update();
-	bv_->cursor().updatePos();
 	fitCursor();
 
 	switchKeyMap();
@@ -892,14 +894,12 @@ bool BufferView::Pimpl::workAreaDispatch
 
 	// If the request was dispatched the temp cursor should have been 
 	// in a way to be used as new 'real' cursor.
-	if (res.dispatched())
+	if (res.dispatched()) {
 		bv_->cursor() = cur;
-
-	// Redraw if requested or necessary.
-	if (res.update())
-		update();
-	if (fitCursor())
-		update();
+		// Redraw if requested or necessary.
+		if (fitCursor() || res.update())
+			update();
+	}
 
 	// see workAreaKeyPress
 	cursor_timeout.restart();
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.85
diff -u -p -u -r1.85 cursor.C
--- cursor.C	1 Apr 2004 08:58:45 -0000	1.85
+++ cursor.C	2 Apr 2004 11:40:38 -0000
@@ -84,8 +84,7 @@ void region(CursorSlice const & i1, Curs
 
 
 LCursor::LCursor(BufferView & bv)
-	: DocIterator(), bv_(&bv),
-	  anchor_(), cached_y_(0), x_target_(-1),
+	: DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
 	  selection_(false), mark_(false)
 {}
 
@@ -95,7 +94,6 @@ void LCursor::reset(InsetBase & inset)
 	clear();
 	push_back(CursorSlice(inset));
 	anchor_ = DocIterator(inset);
-	cached_y_ = 0;
 	clearTargetX();
 	selection_ = false;
 	mark_ = false;
@@ -236,15 +234,6 @@ int LCursor::currentMode()
 }
 
 
-void LCursor::updatePos()
-{
-	BOOST_ASSERT(!empty());
-	if (size() > 1)
-		cached_y_ = bv().top_y() + back().inset().yo();
-		//cached_y_ = back().inset().yo();
-}
-
-
 void LCursor::getDim(int & asc, int & des) const
 {
 	if (inMathed()) {
@@ -270,16 +259,6 @@ void LCursor::getPos(int & x, int & y) c
 	y = 0;
 	if (!empty())
 		inset().getCursorPos(back(), x, y);
-	// getCursorPos gives _screen_ coordinates. We need to add
-	// top_y to get document coordinates. This is hidden in cached_y_.
-	//y += cached_y_ - inset().yo();
-	// The rest is non-obvious. The reason we have to have these
-	// extra computation is that the getCursorPos() calls rely
-	// on the inset's own knowledge of its screen position.
-	// If we scroll up or down in a big enough increment,
-	// inset->draw() is not called: this doesn't update
-	// inset.yo_, so getCursor() returns an old value.
-	// Ugly as you like.
 }
 
 
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.53
diff -u -p -u -r1.53 cursor.h
--- cursor.h	31 Mar 2004 19:11:53 -0000	1.53
+++ cursor.h	2 Apr 2004 11:40:39 -0000
@@ -149,8 +149,6 @@ public:
 	CursorSlice & anchor();
 	/// access to selection anchor
 	CursorSlice const & anchor() const;
-	/// cache the absolute coordinate from the top inset
-	void updatePos();
 	/// sets anchor to cursor position
 	void resetAnchor(); 
 	/// access to owning BufferView
@@ -187,8 +185,6 @@ public:
 	DispatchResult disp_;
 
 private:
-	///
-	int cached_y_;
 	/**
 	 * The target x position of the cursor. This is used for when
 	 * we have text like :
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.604
diff -u -p -u -r1.604 lyxfunc.C
--- lyxfunc.C	1 Apr 2004 08:58:45 -0000	1.604
+++ lyxfunc.C	2 Apr 2004 11:40:40 -0000
@@ -1362,7 +1362,6 @@ void LyXFunc::dispatch(FuncRequest const
 		if (view()->available()) {
 			view()->fitCursor();
 			view()->update();
-			view()->cursor().updatePos();
 			// if we executed a mutating lfun, mark the buffer as dirty
 			if (getStatus(cmd).enabled()
 					&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.240
diff -u -p -u -r1.240 text3.C
--- text3.C	1 Apr 2004 09:05:28 -0000	1.240
+++ text3.C	2 Apr 2004 11:40:41 -0000
@@ -1136,9 +1136,6 @@ void LyXText::dispatch(LCursor & cur, Fu
 		finishUndo();
 		cur.x_target() = cursorX(cur.top());
 
-		if (bv->fitCursor())
-			selection_possible = false;
-
 		// Insert primary selection with middle mouse
 		// if there is a local selection in the current buffer,
 		// insert this
Index: frontends/screen.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/screen.C,v
retrieving revision 1.90
diff -u -p -u -r1.90 screen.C
--- frontends/screen.C	18 Mar 2004 12:53:36 -0000	1.90
+++ frontends/screen.C	2 Apr 2004 11:40:42 -0000
@@ -214,7 +214,7 @@ bool LyXScreen::fitCursor(BufferView * b
 	bv->cursor().getPos(x, y);
 	bv->cursor().getDim(asc, desc);
 	//lyxerr << "LyXScreen::fitCursor: x: " << x << " y: " << y
-	//	<< "  top_y: " << top_y << endl;
+	//      << "  top_y: " << top_y << endl;
 	
 	bool const big_row = h / 4 < asc + desc && asc + desc < h;
 

Reply via email to