From 2fbc66100c01461e32d7c79500ac8b9db993a7b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Thu, 18 Apr 2002 09:47:08 +0000 Subject: [PATCH] Fix page up/down behaviour with very high rows. Same for selection with mouse. (fix #311, #60) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4021 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 125 ++++++++++++++++++++++++++++++----------- src/ChangeLog | 7 +++ src/insets/ChangeLog | 6 ++ src/insets/insettext.C | 17 ++++-- 4 files changed, 115 insertions(+), 40 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index be1e1020be..c1c04f4c1e 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -564,8 +564,27 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state) return; screen_->hideCursor(); - +#if 0 + int y_before = bv_->text->cursor.y(); +#endif + Row * cursorrow = bv_->text->cursor.row(); bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y); +#if 0 + // sorry for this but I have a strange error that the y value jumps at + // a certain point. This seems like an error in my xforms library or + // in some other local environment, but I would like to leave this here + // for the moment until I can remove this (Jug 20020418) + if (y_before < bv_->text->cursor.y()) + lyxerr << y_before << ":" << bv_->text->cursor.y() << endl; +#endif + // This is to allow jumping over large insets + if (cursorrow == bv_->text->cursor.row()) { + if (y >= int(workarea_.height())) { + bv_->text->cursorDown(bv_, false); + } else if (y < 0) { + bv_->text->cursorUp(bv_, false); + } + } if (!bv_->text->selection.set()) update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted @@ -1161,32 +1180,50 @@ void BufferView::Pimpl::cursorToggle() void BufferView::Pimpl::cursorPrevious(LyXText * text) { - if (!text->cursor.row()->previous()) + if (!text->cursor.row()->previous()) { + if (text->first_y > 0) { + int new_y = bv_->text->first_y - workarea_.height(); + screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y); + updateScrollbar(); + } return; + } int y = text->first_y; Row * cursorrow = text->cursor.row(); text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); finishUndo(); - // This is to allow jumping over large insets - if ((cursorrow == text->cursor.row())) - text->cursorUp(bv_); - if (text->inset_owner) { - int new_y = bv_->text->cursor.iy() - + bv_->theLockingInset()->insetInInsetY() - + y - + text->cursor.row()->height() - - workarea_.height() + 1; - - screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y); - } else if (text->cursor.row()->height() < workarea_.height()) { - screen_->draw(text, bv_, - text->cursor.y() - - text->cursor.row()->baseline() - + text->cursor.row()->height() - - workarea_.height() + 1); + int new_y; + if (cursorrow == bv_->text->cursor.row()) { + // we have a row which is higher than the workarea so we leave the + // cursor on the start of the row and move only the draw up as soon + // as we move the cursor or do something while inside the row (it may + // span several workarea-heights) we'll move to the top again, but this + // is better than just jump down and only display part of the row. + new_y = bv_->text->first_y - workarea_.height(); + } else { + if (text->inset_owner) { + new_y = bv_->text->cursor.iy() + + bv_->theLockingInset()->insetInInsetY() + y + + text->cursor.row()->height() + - workarea_.height() + 1; + } else { + new_y = text->cursor.y() + - text->cursor.row()->baseline() + + text->cursor.row()->height() + - workarea_.height() + 1; + } + } + screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y); + if (text->cursor.row()->previous()) { + LyXCursor cur; + text->setCursor(bv_, cur, text->cursor.row()->previous()->par(), + text->cursor.row()->previous()->pos(), false); + if (cur.y() > text->first_y) { + text->cursorUp(bv_, true); + } } updateScrollbar(); } @@ -1194,8 +1231,16 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text) void BufferView::Pimpl::cursorNext(LyXText * text) { - if (!text->cursor.row()->next()) + if (!text->cursor.row()->next()) { + int y = text->cursor.y() - text->cursor.row()->baseline() + + text->cursor.row()->height(); + if (y > int(text->first_y + workarea_.height())) { + screen_->draw(bv_->text, bv_, + bv_->text->first_y + workarea_.height()); + updateScrollbar(); + } return; + } int y = text->first_y + workarea_.height(); if (text->inset_owner && !text->first_y) { @@ -1208,19 +1253,31 @@ void BufferView::Pimpl::cursorNext(LyXText * text) Row * cursorrow = text->cursor.row(); text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height()); finishUndo(); - // This is to allow jumping over large insets - if ((cursorrow == bv_->text->cursor.row())) - text->cursorDown(bv_); - - if (text->inset_owner) { - screen_->draw(bv_->text, bv_, - bv_->text->cursor.iy() - + bv_->theLockingInset()->insetInInsetY() - + y - text->cursor.row()->baseline()); - } else if (text->cursor.irow()->height() < workarea_.height()) { - screen_->draw(text, bv_, text->cursor.y() - - text->cursor.row()->baseline()); - } else { + int new_y; + if (cursorrow == bv_->text->cursor.row()) { + // we have a row which is higher than the workarea so we leave the + // cursor on the start of the row and move only the draw down as soon + // as we move the cursor or do something while inside the row (it may + // span several workarea-heights) we'll move to the top again, but this + // is better than just jump down and only display part of the row. + new_y = bv_->text->first_y + workarea_.height(); + } else { + if (text->inset_owner) { + new_y = bv_->text->cursor.iy() + + bv_->theLockingInset()->insetInInsetY() + + y - text->cursor.row()->baseline(); + } else { + new_y = text->cursor.y() - text->cursor.row()->baseline(); + } + } + screen_->draw(bv_->text, bv_, new_y); + if (text->cursor.row()->next()) { + LyXCursor cur; + text->setCursor(bv_, cur, text->cursor.row()->next()->par(), + text->cursor.row()->next()->pos(), false); + if (cur.y() < int(text->first_y + workarea_.height())) { + text->cursorDown(bv_, true); + } } updateScrollbar(); } @@ -2046,7 +2103,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) update(lt, BufferView::UPDATE); cursorPrevious(lt); finishUndo(); - moveCursorUpdate(false); + moveCursorUpdate(false, false); owner_->showState(); } break; diff --git a/src/ChangeLog b/src/ChangeLog index 174d48c9bd..893ff823bf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-04-18 Juergen Vigna + + * BufferView_pimpl.C (cursorPrevious): + (cursorNext): fixed to make it work with rows heigher than the work + area without moving the cursor only the draw of the row. + (workAreaMotionNotify): fix jumping over high rows. + 2002-04-17 Lars Gullik Bjønnes * lyxtextclass.C (Read): fix bit adding, bug discovered by Mike diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index c94ab7b16a..142561b9f9 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,9 @@ +2002-04-18 Juergen Vigna + + * insettext.C (draw): fixed the setting of LyXText::first_y it was + not really right before, but I only discovered this with the last + changes to Page up/down. + 2002-04-17 Juergen Vigna * insettext.C (checkAndActivateInset): simplified as we now have the diff --git a/src/insets/insettext.C b/src/insets/insettext.C index b35065af69..4a7bf1f2e3 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -451,15 +451,20 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, first += row->height(); row = row->next(); } - if (y_offset < 0) - y_offset = y; - lt->first_y = first; + if (y_offset < 0) { + lt->first_y = -y_offset; + first = y; + y_offset = 0; + } else { + lt->first_y = first; + first = 0; + } if (cleared || (need_update&(INIT|FULL))) { - int yf = y_offset; + int yf = y_offset + first; y = 0; while ((row != 0) && (yf < ph)) { - lt->getVisibleRow(bv, y+y_offset, int(x), row, - y+first, cleared); + lt->getVisibleRow(bv, y+y_offset+first, int(x), row, + y+lt->first_y, cleared); y += row->height(); yf += row->height(); row = row->next(); -- 2.39.2