I've tried something that Angus suggested on the DEPM thread. With this patch, the 'reference' row will be set to the cursor row if visible. This is achieved by adding an anchor_row(Row *) method, and calling that from setCursor if the new cursor row is visible
I've also renamed top_row_ and top_row_offset_ to anchor_row_ and anchor_row_offset_ (the reference row is not forced to be the top row anymore). I've tested it with the UserGuide only. Alfredo
? save2 ? save3 ? trash ? save ? cursor ? save4 Index: ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v retrieving revision 1.1120 diff -u -p -u -r1.1120 ChangeLog --- ChangeLog 2003/03/14 01:49:18 1.1120 +++ ChangeLog 2003/03/14 09:31:10 @@ -1,3 +1,10 @@ +2003-03-14 Alfredo Braunstein <[EMAIL PROTECTED]> + + * text.C: + * lyxtext.h: added anchor_row method, renamed top_row_ => + anchor_row_, top_row_offset => anchor_row_offset_ + * text2.C (setCursor): call to anchor_row + 2003-03-14 John Levon <[EMAIL PROTECTED]> * text2.C: rewrite ::status() a bit Index: lyxtext.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxtext.h,v retrieving revision 1.141 diff -u -p -u -r1.141 lyxtext.h --- lyxtext.h 2003/03/13 21:58:16 1.141 +++ lyxtext.h 2003/03/14 09:31:12 @@ -84,19 +84,22 @@ public: /// the current font mutable LyXFont real_current_font; private: - /** the first visible row on screen + /** the reference row: this one remains fixed on screen + * It's the cursor row if visible or the first visible row * declared mutable because removeRow is const */ - mutable Row * top_row_; + mutable Row * anchor_row_; /** the pixel offset with respect to this row of top_y * declared mutable because removeRow is const */ - mutable int top_row_offset_; + mutable int anchor_row_offset_; public: /// get the y coord. of the top of the screen (relative to doc start) int top_y() const; - /// set it + /// set the y coord. of the top of the screen (relative to doc start) void top_y(int newy); + /// set the anchoring row. top_y will be computed relative to this + void anchor_row(Row * row) const; /// InsetText * inset_owner; /// Index: text.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/text.C,v retrieving revision 1.313 diff -u -p -u -r1.313 text.C --- text.C 2003/03/13 21:19:00 1.313 +++ text.C 2003/03/14 09:31:16 @@ -60,28 +60,42 @@ extern int bibitemMaxWidth(BufferView *, int LyXText::top_y() const { - if (!top_row_) + if (!anchor_row_) return 0; int y = 0; - for (Row * row = firstrow; row && row != top_row_; row = row->next()) { + for (Row * row = firstrow; + row && row != anchor_row_; row = row->next()) { y += row->height(); } - return y + top_row_offset_; + return y + anchor_row_offset_; } -void LyXText::top_y(int newy) +void LyXText::top_y(int newy) { if (!firstrow) return; - lyxerr[Debug::GUI] << "setting top y = " << newy << endl; + lyxerr[Debug::GUI] << "top_y(): setting top y = " << newy << endl; int y = newy; - top_row_ = getRowNearY(y); - top_row_offset_ = newy - y; - lyxerr[Debug::GUI] << "changing reference to row: " << top_row_ - << " offset: " << top_row_offset_ << endl; + anchor_row_ = getRowNearY(y); + anchor_row_offset_ = newy - y; + lyxerr[Debug::GUI] << "top_y(): changing reference to row: " + << anchor_row_ << " offset: " + << anchor_row_offset_ << endl; +} + + +void LyXText::anchor_row(Row * row) const +{ + int old_y = top_y(); + anchor_row_offset_ = 0; + anchor_row_ = row; + anchor_row_offset_ = old_y - top_y(); + lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: " + << anchor_row_ << " offset: " << anchor_row_offset_ + << endl; } Index: text2.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/text2.C,v retrieving revision 1.289 diff -u -p -u -r1.289 text2.C --- text2.C 2003/03/14 01:49:19 1.289 +++ text2.C 2003/03/14 09:31:19 @@ -52,7 +52,7 @@ using lyx::pos_type; LyXText::LyXText(BufferView * bv) - : height(0), width(0), top_row_(0), top_row_offset_(0), + : height(0), width(0), anchor_row_(0), anchor_row_offset_(0), inset_owner(0), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), bv_owner(bv), status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) @@ -60,7 +60,7 @@ LyXText::LyXText(BufferView * bv) LyXText::LyXText(InsetText * inset) - : height(0), width(0), top_row_(0), top_row_offset_(0), + : height(0), width(0), anchor_row_(0), anchor_row_offset_(0), inset_owner(inset), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), bv_owner(0), status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) @@ -326,13 +326,13 @@ void LyXText::removeRow(Row * row) const refresh_row = row_prev ? row_prev : row->next(); // what about refresh_y, refresh_height } - if (top_row_ == row) { + if (anchor_row_ == row) { if (row->next()) { - top_row_ = row->next(); - top_row_offset_ -= row->height(); + anchor_row_ = row->next(); + anchor_row_offset_ -= row->height(); } else { - top_row_ = row_prev; - top_row_offset_ = 0; + anchor_row_ = row_prev; + anchor_row_offset_ = 0; } } @@ -1810,6 +1810,10 @@ void LyXText::setCursor(BufferView * bvi cur.ix(int(x)); } else cur.ix(cur.x()); + //if the cursor is in a visible row, anchor to it + int topy = top_y(); + if (topy < y && y < topy + bview->workHeight()) + anchor_row(row); }