]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
* Doxy: polish html output #2.
[lyx.git] / src / BufferView.cpp
index d7e7e1655e929deb8a5642f295cebfec57c7f543..9edd183157e5309333d5d98bfc10818167e29bf9 100644 (file)
@@ -501,6 +501,13 @@ docstring BufferView::contextMenu(int x, int y) const
 
 void BufferView::scrollDocView(int value)
 {
+       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_) {
+               scroll(offset);
+               return;
+       }
+
        // cut off at the top
        if (value <= d->scrollbarParameters_.min) {
                DocIterator dit = doc_iterator_begin(buffer_.inset());
@@ -509,7 +516,7 @@ void BufferView::scrollDocView(int value)
                return;
        }
 
-       // cut off at the top
+       // cut off at the bottom
        if (value >= d->scrollbarParameters_.max) {
                DocIterator dit = doc_iterator_end(buffer_.inset());
                dit.backwardPos();
@@ -518,39 +525,27 @@ void BufferView::scrollDocView(int value)
                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_) {
-               scroll(offset);
-               return;
-       }
-
-       // find paragraph at target positin
+       // find paragraph at target position
        int par_pos = d->scrollbarParameters_.min;
-       for (size_t i = 0; i != d->par_height_.size(); ++i) {
+       pit_type i = 0;
+       for (; i != d->par_height_.size(); ++i) {
                par_pos += d->par_height_[i];
-               if (par_pos >= value) {
-                       d->anchor_pit_ = pit_type(i);
+               if (par_pos >= value)
                        break;
-               }
        }
 
-       LYXERR(Debug::SCROLLING, "value = " << value
-               << "\tanchor_ref_ = " << d->anchor_pit_
-               << "\tpar_pos = " << par_pos);
-
-       // cut off at the end of the buffer
-       if (value > par_pos) {
-               value = d->scrollbarParameters_.max;
-               d->anchor_pit_ = d->par_height_.size() - 1;
+       if (par_pos < value) {
+               // It seems we didn't find the correct pit so stay on the safe side and
+               // scroll to bottom.
+               LYXERR0("scrolling position not found!");
+               scrollDocView(d->scrollbarParameters_.max);
+               return;
        }
 
-       // set pixel offset of screen to anchor pit
-       d->anchor_ypos_ = par_pos - value;
-
-       updateMetrics();
-       buffer_.changed();
+       DocIterator dit = doc_iterator_begin(buffer_.inset());
+       dit.pit() = i;
+       LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
+       showCursor(dit);
 }