diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 70117c8f87..f19afde738 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1462,7 +1462,8 @@ bool BufferView::dispatch(FuncRequest const & cmd) cur.reset(buffer_.inset()); updateMetrics(); buffer_.changed(); - d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_); + d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_, + true, cmd.action == LFUN_SCREEN_UP); //FIXME: what to do with cur.x_target()? bool update = false; if (in_texted) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index ca436b1a92..a9bd7daefe 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1370,7 +1370,8 @@ pit_type TextMetrics::getPitNearY(int y) } -Row const & TextMetrics::getRowNearY(int y, pit_type pit) const +Row const & TextMetrics::getPitAndRowNearY(int y, pit_type & pit, + bool assert_in_view, bool up) { ParagraphMetrics const & pm = par_metrics_[pit]; @@ -1382,13 +1383,37 @@ Row const & TextMetrics::getRowNearY(int y, pit_type pit) const for (; rit != rlast; yy += rit->height(), ++rit) if (yy + rit->height() > y) break; + + if (assert_in_view && yy + rit->height() != y) { + if (!up) { + if (rit != pm.rows().begin()) + --rit; + else if (pit != 0) { + --pit; + newParMetricsUp(); + ParagraphMetrics const & pm2 = par_metrics_[pit]; + rit = pm2.rows().end(); + --rit; + } + } else { + if (rit != rlast) + ++rit; + else if (pit != int(par_metrics_.size())) { + ++pit; + newParMetricsDown(); + ParagraphMetrics const & pm2 = par_metrics_[pit]; + rit = pm2.rows().begin(); + } + } + } return *rit; } // x,y are absolute screen coordinates // sets cursor recursively descending into nested editable insets -Inset * TextMetrics::editXY(Cursor & cur, int x, int y) +Inset * TextMetrics::editXY(Cursor & cur, int x, int y, + bool assert_in_view, bool up) { if (lyxerr.debugging(Debug::WORKAREA)) { LYXERR0("TextMetrics::editXY(cur, " << x << ", " << y << ")"); @@ -1397,7 +1422,7 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y) pit_type pit = getPitNearY(y); LASSERT(pit != -1, return 0); - Row const & row = getRowNearY(y, pit); + Row const & row = getPitAndRowNearY(y, pit, assert_in_view, up); bool bound = false; int xx = x; // is modified by getColumnNearX diff --git a/src/TextMetrics.h b/src/TextMetrics.h index 78825c3985..606d67523a 100644 --- a/src/TextMetrics.h +++ b/src/TextMetrics.h @@ -176,11 +176,11 @@ public: // FIXME: is there a need for this? //int pos2x(pit_type pit, pos_type pos) const; - /** returns row near the specified - * y-coordinate in given paragraph (relative to the screen). - */ - Row const & getRowNearY(int y, - pit_type pit) const; + /// returns the row near the specified y-coordinate in a given paragraph + /// (relative to the screen). If assert_in_view is true, it is made sure + /// that the row is on screen completely; this might change the given pit. + Row const & getPitAndRowNearY(int y, pit_type & pit, + bool assert_in_view, bool up); /// returns the paragraph number closest to screen y-coordinate. /// This method uses the BufferView CoordCache to locate the @@ -193,11 +193,16 @@ public: /** \return the inset pointer if x,y is covering that inset \param x,y are absolute screen coordinates. + \param assert_in_view if true the cursor will be set on a row + that is completely visible + \param up whether we are going up or down (only used when + assert_in_view is true \retval inset is non-null if the cursor is positionned inside */ /// FIXME: cleanup to use BufferView::getCoveringInset() and /// setCursorFromCoordinates() instead of checkInsetHit(). - Inset * editXY(Cursor & cur, int x, int y); + Inset * editXY(Cursor & cur, int x, int y, + bool assert_in_view = false, bool up = true); /// sets cursor only within this Text. /// x,y are screen coordinates diff --git a/status.16x b/status.16x index 1bbd83db8b..72ad027806 100644 --- a/status.16x +++ b/status.16x @@ -216,6 +216,11 @@ What's new - Remove empty paragraphs and superfluous spaces when leaving an inset (bug 5435). +- Fix the scrolling problem that when scrolling with PgUp or PgDn, the + cursor could end up on a row that is only partly visible. This causes + the cursor to end up somewhere else when scrolling back (bug 5944). + + * DOCUMENTATION AND LOCALIZATION - Fix icon image files so that they appear correctly when the