From: Jürgen Vigna Date: Thu, 11 Apr 2002 09:53:23 +0000 (+0000) Subject: Fix the cursor position to be on the end of the row before an inset which X-Git-Tag: 1.6.10~19440 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8f1a6ffaed147286a10ffa738edadbf4c5ff25a1;p=features.git Fix the cursor position to be on the end of the row before an inset which needs a full row (#44). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3966 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView2.C b/src/BufferView2.C index fa9456ea50..90f7e3e9fb 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -572,7 +572,7 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc) shape = (txt->real_current_font.isVisibleRightToLeft()) ? LyXScreen::REVERSED_L_SHAPE : LyXScreen::L_SHAPE; - y += cursor.y() + theLockingInset()->insetInInsetY(); + y += cursor.iy() + theLockingInset()->insetInInsetY(); pimpl_->screen_->showManualCursor(text, x, y, asc, desc, shape); } @@ -590,7 +590,7 @@ void BufferView::hideLockedInsetCursor() bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc) { if (theLockingInset() && available()) { - y += text->cursor.y() + theLockingInset()->insetInInsetY(); + y += text->cursor.iy() + theLockingInset()->insetInInsetY(); if (pimpl_->screen_->fitManualCursor(text, this, x, y, asc, desc)) { updateScrollbar(); return true; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index cad89d3fdf..1549d3338a 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -951,7 +951,7 @@ Inset * BufferView::Pimpl::checkInset(LyXText const & text, x -= b.x1; // The origin of an inset is on the baseline - y -= (text.cursor.y()); + y -= text.cursor.iy(); return inset; } diff --git a/src/ChangeLog b/src/ChangeLog index 1a242e948a..564ac4e52c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2002-04-11 Juergen Vigna + + * BufferView2.C (showLockedInsetCursor): use iy + (fitLockedInsetCursor): ditto + + * BufferView_pimpl.C (checkInset): use LyXCursor::iy for baseline of + locked insets as there we have the right value now. + + * lyxcursor.C: added iy_ variable and iy functions to set to the + baseline of cursor-y of the locked inset. + + * text2.C (setCursorFromCoordinates): set LyXCursor::iy. + (setCursor): fixed for insets which need a full row. + + * text.C (rowLastPrintable): don't ignore the last space when before + an inset which needs a full row. + (numberOfSeparators): use rowLastPrintable and <= last to honor a space + as last character of a row when before a inset which needs a full row. + 2002-04-06 Lars Gullik Bjønnes * version.C.in: update date diff --git a/src/lyxcursor.C b/src/lyxcursor.C index 76e43f76ba..4e02327fbc 100644 --- a/src/lyxcursor.C +++ b/src/lyxcursor.C @@ -19,7 +19,7 @@ LyXCursor::LyXCursor() : par_(0), pos_(0), boundary_(false), - x_(0), x_fix_(0), y_(0), row_(0) + x_(0), x_fix_(0), y_(0), iy_(0), row_(0) {} @@ -94,6 +94,18 @@ int LyXCursor::y() const } +void LyXCursor::iy(int i) +{ + iy_ = i; +} + + +int LyXCursor::iy() const +{ + return iy_; +} + + void LyXCursor::row(Row * r) { row_ = r; diff --git a/src/lyxcursor.h b/src/lyxcursor.h index c36812befd..9c37d0dff9 100644 --- a/src/lyxcursor.h +++ b/src/lyxcursor.h @@ -52,6 +52,10 @@ public: /// int y() const; /// + void iy(int i); + /// + int iy() const; + /// void row(Row * r); /// Row * row() const; @@ -68,6 +72,9 @@ private: int x_fix_; /// int y_; + /// the y position of the position before the inset when we put + /// the cursor on the end of the row before, otherwise equal to y. + int iy_; /// Row * row_; }; diff --git a/src/text.C b/src/text.C index 6898b18145..7bbca3dfee 100644 --- a/src/text.C +++ b/src/text.C @@ -254,10 +254,21 @@ pos_type LyXText::rowLast(Row const * row) const pos_type LyXText::rowLastPrintable(Row const * row) const { pos_type const last = rowLast(row); + bool ignore_the_space_on_the_last_position = true; + Inset * ins; + // we have to consider a space on the last position in this case! + if (row->next() && row->par() == row->next()->par() && + row->next()->par()->getChar(last+1) == Paragraph::META_INSET && + (ins=row->next()->par()->getInset(last+1)) && + (ins->needFullRow() || ins->display())) + { + ignore_the_space_on_the_last_position = false; + } if (last >= row->pos() && row->next() && row->next()->par() == row->par() - && row->par()->isSeparator(last)) + && row->par()->isSeparator(last) + && ignore_the_space_on_the_last_position) return last - 1; else return last; @@ -1134,10 +1145,11 @@ int LyXText::labelFill(BufferView * bview, Row const * row) const // on the very last column doesnt count int LyXText::numberOfSeparators(Buffer const * buf, Row const * row) const { - pos_type const last = rowLast(row); + pos_type last = rowLastPrintable(row); pos_type p = max(row->pos(), beginningOfMainBody(buf, row->par())); + int n = 0; - for (; p < last; ++p) { + for (; p <= last; ++p) { if (row->par()->isSeparator(p)) { ++n; } diff --git a/src/text2.C b/src/text2.C index 6479cf7c15..5b6f639769 100644 --- a/src/text2.C +++ b/src/text2.C @@ -2061,20 +2061,23 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par, cur.pos(pos); cur.boundary(boundary); -#if 0 - if (pos && par->getChar(pos) == Paragraph::META_INSET && - par->getInset(pos)) { - Inset * ins = par->getInset(pos); - if (ins->needFullRow() || ins->display()) { - --pos; - boundary = true; - } - } -#endif - // get the cursor y position in text int y = 0; Row * row = getRow(par, pos, y); + Row * old_row = row; + // if we are before the first char of this row and are still in the + // same paragraph and there is a previous row then put the cursor on + // the end of the previous row + cur.iy(y + row->baseline()); + Inset * ins; + if (pos && par->getChar(pos) == Paragraph::META_INSET && + (ins=par->getInset(pos)) && (ins->needFullRow() || ins->display())) + { + row = row->previous(); + y -= row->height(); + } + + cur.row(row); // y is now the beginning of the cursor row y += row->baseline(); // y is now the cursor baseline @@ -2088,7 +2091,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par, prepareToPrint(bview, row, x, fill_separator, fill_hfill, fill_label_hfill); pos_type cursor_vpos = 0; - pos_type last = rowLastPrintable(row); + pos_type last = rowLastPrintable(old_row); if (pos > last + 1) { // This shouldn't happen. @@ -2149,7 +2152,6 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par, cur.x(int(x)); cur.x_fix(cur.x()); - cur.row(row); } @@ -2247,6 +2249,7 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur, cur.pos(row->pos() + column); cur.x(x); cur.y(y + row->baseline()); + cur.iy(cur.y()); cur.row(row); cur.boundary(bound); }