From 81e06f7bc9cddbd9d553681a08eadbc8e04a0447 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 29 Jan 2008 09:51:12 +0000 Subject: [PATCH] Fix scrolling to top and bottom of the document. * BufferView - showCursor(DocIterator): new DocIterator argument. - showCursor(): use above method. - scrollDocView(): take care of top and bottom special cases early in the method. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22707 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 46 ++++++++++++++++++++++++++++++++++++---------- src/BufferView.h | 8 ++++++-- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index e563a4f81d..d7e7e1655e 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -501,6 +501,24 @@ docstring BufferView::contextMenu(int x, int y) const void BufferView::scrollDocView(int value) { + // cut off at the top + if (value <= d->scrollbarParameters_.min) { + DocIterator dit = doc_iterator_begin(buffer_.inset()); + showCursor(dit); + LYXERR(Debug::SCROLLING, "scroll to top"); + return; + } + + // cut off at the top + if (value >= d->scrollbarParameters_.max) { + DocIterator dit = doc_iterator_end(buffer_.inset()); + dit.backwardPos(); + showCursor(dit); + LYXERR(Debug::SCROLLING, "scroll to bottom"); + return; + } + + int const offset = value - d->scrollbarParameters_.position; // If the offset is less than 2 screen height, prefer to scroll instead. if (abs(offset) <= 2 * height_) { @@ -508,10 +526,6 @@ void BufferView::scrollDocView(int value) return; } - // cut off at the top - if (value < d->scrollbarParameters_.min) - value = d->scrollbarParameters_.min; - // find paragraph at target positin int par_pos = d->scrollbarParameters_.min; for (size_t i = 0; i != d->par_height_.size(); ++i) { @@ -703,6 +717,12 @@ int BufferView::workWidth() const void BufferView::showCursor() +{ + showCursor(d->cursor_); +} + + +void BufferView::showCursor(DocIterator const & dit) { // We are not properly started yet, delay until resizing is // done. @@ -711,11 +731,11 @@ void BufferView::showCursor() LYXERR(Debug::SCROLLING, "recentering!"); - CursorSlice & bot = d->cursor_.bottom(); + CursorSlice const & bot = dit.bottom(); TextMetrics & tm = d->text_metrics_[bot.text()]; pos_type const max_pit = pos_type(bot.text()->paragraphs().size() - 1); - int bot_pit = d->cursor_.bottom().pit(); + int bot_pit = bot.pit(); if (bot_pit > max_pit) { // FIXME: Why does this happen? LYXERR0("bottom pit is greater that max pit: " @@ -730,9 +750,13 @@ void BufferView::showCursor() if (tm.has(bot_pit)) { ParagraphMetrics const & pm = tm.parMetrics(bot_pit); - int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_; + BOOST_ASSERT(!pm.rows().empty()); + // FIXME: smooth scrolling doesn't work in mathed. + CursorSlice const & cs = dit.innerTextSlice(); + int offset = coordOffset(dit, dit.boundary()).y_; int ypos = pm.position() + offset; - Dimension const & row_dim = d->cursor_.textRow().dimension(); + Dimension const & row_dim = + pm.getRow(cs.pos(), dit.boundary()).dimension(); if (ypos - row_dim.ascent() < 0) scrollUp(- ypos + row_dim.ascent()); else if (ypos + row_dim.descent() > height_) @@ -743,10 +767,12 @@ void BufferView::showCursor() tm.redoParagraph(bot_pit); ParagraphMetrics const & pm = tm.parMetrics(bot_pit); - int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_; + int offset = coordOffset(dit, dit.boundary()).y_; d->anchor_pit_ = bot_pit; - Dimension const & row_dim = d->cursor_.textRow().dimension(); + CursorSlice const & cs = dit.innerTextSlice(); + Dimension const & row_dim = + pm.getRow(cs.pos(), dit.boundary()).dimension(); if (d->anchor_pit_ == 0) d->anchor_ypos_ = offset + pm.ascent(); diff --git a/src/BufferView.h b/src/BufferView.h index faac2f6c62..2fe0064188 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -127,10 +127,14 @@ public: /// set the cursor based on the given TeX source row. void setCursorFromRow(int row); - /// Ensure the cursor is visible. - /// This method will automatically scroll and update the BufferView and updated + /// Ensure that the BufferView cursor is visible. + /// This method will automatically scroll and update the BufferView /// if needed. void showCursor(); + /// Ensure the passed cursor \p dit is visible. + /// This method will automatically scroll and update the BufferView + /// if needed. + void showCursor(DocIterator const & dit); /// LFUN_SCROLL Helper. void lfunScroll(FuncRequest const & cmd); /// scroll down document by the given number of pixels. -- 2.39.5