From 3ea0a9e5f451ca35c67adca1ee4ee315e316260b Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 18 Mar 2003 16:47:18 +0000 Subject: [PATCH] anchorRow git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6526 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 6 ++++++ src/lyxtext.h | 11 +++++++---- src/text.C | 27 ++++++++++++++++++++------- src/text2.C | 20 ++++++++++++-------- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a8f0f528b3..3543415d93 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-03-18 Alfredo Braunstein + + * lyxtext.h: + * text.C: + * text2.C: anchor row on setCursor + 2003-03-18 Alfredo Braunstein * lyxtext.h: remove almost all mutable keywords diff --git a/src/lyxtext.h b/src/lyxtext.h index e880d878c4..a7446769db 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -84,17 +84,20 @@ public: /// the current font LyXFont real_current_font; private: - /** the first visible row on screen + /** the 'anchor' row: the position of this row remains constant + * with respect to the top of the screen */ - Row * top_row_; + Row * anchor_row_; /** the pixel offset with respect to this row of top_y */ - int top_row_offset_; + 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); /// InsetText * inset_owner; /// diff --git a/src/text.C b/src/text.C index e1239f2878..5235f1611f 100644 --- a/src/text.C +++ b/src/text.C @@ -74,14 +74,15 @@ BufferView * LyXText::bv() const 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_; } @@ -92,10 +93,22 @@ void LyXText::top_y(int newy) lyxerr[Debug::GUI] << "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] << "changing reference to row: " << anchor_row_ + << " offset: " << anchor_row_offset_ << endl; +} + + +void LyXText::anchor_row(Row * row) +{ + 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; } diff --git a/src/text2.C b/src/text2.C index 75126e96c0..29ebcd2d13 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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), bv_owner(bv), firstrow(0), lastrow(0) { @@ -61,7 +61,7 @@ LyXText::LyXText(BufferView * bv) LyXText::LyXText(BufferView * bv, 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), bv_owner(bv), firstrow(0), lastrow(0) { @@ -331,13 +331,13 @@ void LyXText::removeRow(Row * row) // what about refresh_y } - if (top_row_ == row) { - if (row->next()) { - top_row_ = row->next(); - top_row_offset_ -= row->height(); + if (anchor_row_ == row) { + if (row_prev) { + anchor_row_ = row_prev; + anchor_row_offset_ = 0; } else { - top_row_ = row_prev; - top_row_offset_ = 0; + anchor_row_ = row->next(); + anchor_row_offset_ -= row->height(); } } @@ -1793,6 +1793,10 @@ void LyXText::setCursor(LyXCursor & cur, Paragraph * par, 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 + bv()->workHeight()) + anchor_row(row); } -- 2.39.2