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
This commit is contained in:
Jürgen Vigna 2002-04-11 09:53:23 +00:00
parent 68bc4b573a
commit 8f1a6ffaed
7 changed files with 73 additions and 20 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -1,3 +1,22 @@
2002-04-11 Juergen Vigna <jug@sad.it>
* 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 <larsbj@birdstep.com>
* version.C.in: update date

View File

@ -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;

View File

@ -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_;
};

View File

@ -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;
}

View File

@ -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);
}