]> git.lyx.org Git - features.git/commitdiff
Fix page up/down behaviour with very high rows. Same for selection with mouse.
authorJürgen Vigna <jug@sad.it>
Thu, 18 Apr 2002 09:47:08 +0000 (09:47 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 18 Apr 2002 09:47:08 +0000 (09:47 +0000)
(fix #311, #60)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4021 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/ChangeLog
src/insets/ChangeLog
src/insets/insettext.C

index be1e1020be14f96ed295139960179bd0de536acc..c1c04f4c1ecd5cf9865d8f644f5bb8eaf1daeff7 100644 (file)
@@ -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;
index 174d48c9bd9fb9f404d44f8309ae3667fd44b647..893ff823bfa2036ea82b550c72df9855d3295e93 100644 (file)
@@ -1,3 +1,10 @@
+2002-04-18  Juergen Vigna  <jug@sad.it>
+
+       * 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  <larsbj@birdstep.com>
 
        * lyxtextclass.C (Read): fix bit adding, bug discovered by Mike
index c94ab7b16ac4308f93c7eb7a656b0e9fb7e592f9..142561b9f9a9f32bd9e1bcd5ec49f20d137256cc 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-18  Juergen Vigna  <jug@sad.it>
+
+       * 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  <jug@sad.it>
 
        * insettext.C (checkAndActivateInset): simplified as we now have the
index b35065af69da726944d5a024d99c452f3b8faa29..4a7bf1f2e3053991386a9a761e8153181c8388d3 100644 (file)
@@ -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();