Compare commits

..

No commits in common. "9c443d965114318dacbb67db68f5a3fd9b1b8fc2" and "f52842d289d1434c44ffb4c9971279a8e56af612" have entirely different histories.

2 changed files with 52 additions and 49 deletions

View File

@ -2128,8 +2128,6 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
case LFUN_SCREEN_UP: case LFUN_SCREEN_UP:
case LFUN_SCREEN_DOWN: { case LFUN_SCREEN_DOWN: {
Point p = getPos(cur); Point p = getPos(cur);
// replace x by the cursor target
p.x = cur.targetX();
// This code has been commented out to enable to scroll down a // This code has been commented out to enable to scroll down a
// document, even if there are large insets in it (see bug #5465). // document, even if there are large insets in it (see bug #5465).
/*if (p.y < 0 || p.y > height_) { /*if (p.y < 0 || p.y > height_) {
@ -2137,28 +2135,29 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
showCursor(); showCursor();
p = getPos(cur); p = getPos(cur);
}*/ }*/
scroll(act == LFUN_SCREEN_UP ? -height_ : height_); int const scrolled = scroll(act == LFUN_SCREEN_UP
// update metrics ? -height_ : height_);
int const correction = updateMetrics(false); if (act == LFUN_SCREEN_UP && scrolled > -height_)
if (act == LFUN_SCREEN_UP && correction < 0) p = Point(0, 0);
p = Point(lyxrc.mac_like_cursor_movement ? 0 : p.x, 0); if (act == LFUN_SCREEN_DOWN && scrolled < height_)
if (act == LFUN_SCREEN_DOWN && correction > 0) p = Point(width_, height_);
p = Point(lyxrc.mac_like_cursor_movement ? width_ : p.x, height_);
bool const in_texted = cur.inTexted(); bool const in_texted = cur.inTexted();
cur.setCursor(doc_iterator_begin(cur.buffer())); cur.setCursor(doc_iterator_begin(cur.buffer()));
cur.selHandle(false); cur.selHandle(false);
// Force an immediate computation of metrics because we need it below
if (scrolled)
processUpdateFlags(Update::Force);
d->text_metrics_[&buffer_.text()].editXY(cur, p.x, p.y, d->text_metrics_[&buffer_.text()].editXY(cur, p.x, p.y,
false, act == LFUN_SCREEN_UP); true, act == LFUN_SCREEN_UP);
//FIXME: what to do with cur.x_target()? //FIXME: what to do with cur.x_target()?
bool update = in_texted && cur.bv().checkDepm(cur, old); bool update = in_texted && cur.bv().checkDepm(cur, old);
cur.finishUndo(); cur.finishUndo();
if (update) { if (update || cur.mark())
dr.screenUpdate(Update::Force | Update::FitCursor); dr.screenUpdate(Update::Force | Update::FitCursor);
if (update)
dr.forceBufferUpdate(); dr.forceBufferUpdate();
} else
dr.screenUpdate(Update::ForceDraw | Update::FitCursor);
break; break;
} }
@ -2169,24 +2168,18 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
scroll_step = d->scrollbarParameters_.single_step; scroll_step = d->scrollbarParameters_.single_step;
else if (scroll_type == "page") else if (scroll_type == "page")
scroll_step = d->scrollbarParameters_.page_step; scroll_step = d->scrollbarParameters_.page_step;
else { else
dispatched = false;
return; return;
}
string const scroll_quantity = cmd.getArg(1); string const scroll_quantity = cmd.getArg(1);
if (scroll_quantity == "up") if (scroll_quantity == "up")
scroll(-scroll_step); scrollUp(scroll_step);
else if (scroll_quantity == "down") else if (scroll_quantity == "down")
scroll(scroll_step); scrollDown(scroll_step);
else if (isStrInt(scroll_quantity))
scroll(scroll_step * convert<int>(scroll_quantity));
else { else {
dispatched = false; int const scroll_value = convert<int>(scroll_quantity);
return; if (scroll_value)
scroll(scroll_step * scroll_value);
} }
dr.screenUpdate(Update::ForceDraw); dr.screenUpdate(Update::ForceDraw);
dr.forceBufferUpdate(); dr.forceBufferUpdate();
break; break;
@ -2859,9 +2852,24 @@ int BufferView::minVisiblePart()
} }
void BufferView::scroll(int pixels) int BufferView::scroll(int pixels)
{ {
d->anchor_ypos_ -= pixels; d->anchor_ypos_ -= pixels;
return -pixels;
}
int BufferView::scrollDown(int pixels)
{
d->anchor_ypos_ -= pixels;
return -pixels;
}
int BufferView::scrollUp(int pixels)
{
d->anchor_ypos_ += pixels;
return pixels;
} }
@ -3220,10 +3228,10 @@ void BufferView::updateMetrics()
} }
int BufferView::updateMetrics(bool force) void BufferView::updateMetrics(bool force)
{ {
if (!ready()) if (!ready())
return 0; return;
//LYXERR0("updateMetrics " << _v_(force)); //LYXERR0("updateMetrics " << _v_(force));
@ -3256,7 +3264,6 @@ int BufferView::updateMetrics(bool force)
tm.updateMetrics(d->anchor_pit_, d->anchor_ypos_, height_); tm.updateMetrics(d->anchor_pit_, d->anchor_ypos_, height_);
// Check that the end of the document is not too high // Check that the end of the document is not too high
int const old_ypos = d->anchor_ypos_;
int const min_visible = lyxrc.scroll_below_document ? minVisiblePart() : height_; int const min_visible = lyxrc.scroll_below_document ? minVisiblePart() : height_;
if (tm.last().first == lastpit && tm.last().second->hasPosition() if (tm.last().first == lastpit && tm.last().second->hasPosition()
&& tm.last().second->bottom() < min_visible) { && tm.last().second->bottom() < min_visible) {
@ -3273,9 +3280,6 @@ int BufferView::updateMetrics(bool force)
tm.updateMetrics(d->anchor_pit_, d->anchor_ypos_, height_); tm.updateMetrics(d->anchor_pit_, d->anchor_ypos_, height_);
} }
// The global adjustment that have been made above
int const correction = d->anchor_ypos_ - old_ypos;
/* FIXME: do we want that? It avoids potential issues with old /* FIXME: do we want that? It avoids potential issues with old
* paragraphs that should have been recomputed but have not, at * paragraphs that should have been recomputed but have not, at
* the price of potential extra metrics computation. I do not * the price of potential extra metrics computation. I do not
@ -3311,7 +3315,6 @@ int BufferView::updateMetrics(bool force)
LYXERR(Debug::WORKAREA, "BufferView::updateMetrics"); LYXERR(Debug::WORKAREA, "BufferView::updateMetrics");
d->coord_cache_.dump(); d->coord_cache_.dump();
} }
return correction;
} }

View File

@ -218,18 +218,18 @@ public:
/// Ensure the passed cursor \p dit is visible. /// Ensure the passed cursor \p dit is visible.
/// This method will automatically scroll and update the BufferView /// This method will automatically scroll and update the BufferView
/// (metrics+drawing) if needed. /// (metrics+drawing) if needed.
/// \param how: where the cursor should appear (visible/top/center) /// \param how Use this scroll strategy
void showCursor(DocIterator const & dit, ScrollType how); void showCursor(DocIterator const & dit, ScrollType how);
/// Scroll to the cursor. /// Scroll to the cursor.
/// This only updates the anchor vertical position, but does not /// \param how Use this scroll strategy
/// recompute metrics nor trigger a screen refresh.
/// \param how: where the cursor should appear (visible/top/center)
/// \return true if screen was scrolled /// \return true if screen was scrolled
bool scrollToCursor(DocIterator const & dit, ScrollType how); bool scrollToCursor(DocIterator const & dit, ScrollType how);
/// scroll the view by the given number of pixels. This only /// scroll down document by the given number of pixels.
/// updates the anchor vertical position, but does not recompute int scrollDown(int pixels);
/// metrics nor trigger a screen refresh. /// scroll up document by the given number of pixels.
void scroll(int pixels); int scrollUp(int pixels);
/// scroll document by the given number of pixels.
int scroll(int pixels);
/// Scroll the view by a number of pixels. /// Scroll the view by a number of pixels.
void scrollDocView(int pixels); void scrollDocView(int pixels);
/// Set the cursor position based on the scrollbar one. /// Set the cursor position based on the scrollbar one.
@ -418,15 +418,15 @@ private:
/// Update current paragraph metrics. /// Update current paragraph metrics.
/// \return true if no further update is needed. /// \return true if no further update is needed.
bool singleParUpdate(); bool singleParUpdate();
/** Helper for the public updateMetrics() and for processUpdateFlags(). /** Helper for the public updateMetrics() and for processUpdateFlags()
* This does also set the anchor paragraph and its position correctly. * * When \c force is true, get rid of all paragraph metrics and
* \param force when true, get rid of all paragraph metrics and rebuild them anew.
* rebuild them anew. Otherwise keep the paragraphs that are * * When it is false, keep the paragraphs that are still visible in
* still visible in work area and rebuild the missing ones. * WorkArea and rebuild the missing ones.
* \return the correction needed (same sign as anchor vertical *
* position change) when hitting top or bottom constraints. * This does also set the anchor paragraph and its position correctly
*/ */
int updateMetrics(bool force); void updateMetrics(bool force);
// Set the row on which the cursor lives. // Set the row on which the cursor lives.
void setCurrentRowSlice(CursorSlice const & rowSlice); void setCurrentRowSlice(CursorSlice const & rowSlice);