mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Make sure paragraph positions are updated when scrolling
Sometimes quick selection-scrolling could cause a crash because the
position of some paragraphs is not computed. To fix that, in
BufferView::showCursor, make sure that the metrics are always kept
clean using updateMetrics(false), which is lighweight.
As a consequence, the 'update' parameter of showCursor and
scrollDocView is not needed anymore. Its removal is mechanical and
accounts for most of this commit.
The only other significant change is that, when creating synthetic
mouse events and relying on scroll() for small moves, the full metrics
recomputation is replaced by the lighter version.
More work is still to come on this code, but this should be going in
the right direction.
(cherry picked from commit 6e0ea4269a
)
This commit is contained in:
parent
10b8861d10
commit
2886843560
@ -755,7 +755,7 @@ Inset const * BufferView::mathContextMenu(InsetMathNest const * inset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BufferView::scrollDocView(int const pixels, bool update)
|
void BufferView::scrollDocView(int const pixels)
|
||||||
{
|
{
|
||||||
// The scrollbar values are relative to the top of the screen, therefore the
|
// The scrollbar values are relative to the top of the screen, therefore the
|
||||||
// offset is equal to the target value.
|
// offset is equal to the target value.
|
||||||
@ -778,7 +778,7 @@ void BufferView::scrollDocView(int const pixels, bool update)
|
|||||||
// cut off at the top
|
// cut off at the top
|
||||||
if (pixels <= d->scrollbarParameters_.min) {
|
if (pixels <= d->scrollbarParameters_.min) {
|
||||||
DocIterator dit = doc_iterator_begin(&buffer_);
|
DocIterator dit = doc_iterator_begin(&buffer_);
|
||||||
showCursor(dit, SCROLL_VISIBLE, update);
|
showCursor(dit, SCROLL_VISIBLE);
|
||||||
LYXERR(Debug::SCROLLING, "scroll to top");
|
LYXERR(Debug::SCROLLING, "scroll to top");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -787,7 +787,7 @@ void BufferView::scrollDocView(int const pixels, bool update)
|
|||||||
if (pixels >= d->scrollbarParameters_.max) {
|
if (pixels >= d->scrollbarParameters_.max) {
|
||||||
DocIterator dit = doc_iterator_end(&buffer_);
|
DocIterator dit = doc_iterator_end(&buffer_);
|
||||||
dit.backwardPos();
|
dit.backwardPos();
|
||||||
showCursor(dit, SCROLL_VISIBLE, update);
|
showCursor(dit, SCROLL_VISIBLE);
|
||||||
LYXERR(Debug::SCROLLING, "scroll to bottom");
|
LYXERR(Debug::SCROLLING, "scroll to bottom");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -806,14 +806,14 @@ void BufferView::scrollDocView(int const pixels, bool update)
|
|||||||
// It seems we didn't find the correct pit so stay on the safe side and
|
// It seems we didn't find the correct pit so stay on the safe side and
|
||||||
// scroll to bottom.
|
// scroll to bottom.
|
||||||
LYXERR0("scrolling position not found!");
|
LYXERR0("scrolling position not found!");
|
||||||
scrollDocView(d->scrollbarParameters_.max, update);
|
scrollDocView(d->scrollbarParameters_.max);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DocIterator dit = doc_iterator_begin(&buffer_);
|
DocIterator dit = doc_iterator_begin(&buffer_);
|
||||||
dit.pit() = i;
|
dit.pit() = i;
|
||||||
LYXERR(Debug::SCROLLING, "pixels = " << pixels << " -> scroll to pit " << i);
|
LYXERR(Debug::SCROLLING, "pixels = " << pixels << " -> scroll to pit " << i);
|
||||||
showCursor(dit, SCROLL_VISIBLE, update);
|
showCursor(dit, SCROLL_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -999,21 +999,20 @@ int BufferView::workWidth() const
|
|||||||
|
|
||||||
void BufferView::recenter()
|
void BufferView::recenter()
|
||||||
{
|
{
|
||||||
showCursor(d->cursor_, SCROLL_CENTER, true);
|
showCursor(d->cursor_, SCROLL_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BufferView::showCursor()
|
void BufferView::showCursor()
|
||||||
{
|
{
|
||||||
showCursor(d->cursor_, SCROLL_VISIBLE, true);
|
showCursor(d->cursor_, SCROLL_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BufferView::showCursor(DocIterator const & dit, ScrollType how,
|
void BufferView::showCursor(DocIterator const & dit, ScrollType how)
|
||||||
bool update)
|
|
||||||
{
|
{
|
||||||
if (scrollToCursor(dit, how) && update)
|
if (scrollToCursor(dit, how))
|
||||||
processUpdateFlags(Update::Force);
|
processUpdateFlags(Update::ForceDraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,8 +219,7 @@ public:
|
|||||||
/// 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 Use this scroll strategy
|
/// \param how Use this scroll strategy
|
||||||
/// \param force If true, update screen after scrolling
|
void showCursor(DocIterator const & dit, ScrollType how);
|
||||||
void showCursor(DocIterator const & dit, ScrollType how, bool update);
|
|
||||||
/// Scroll to the cursor.
|
/// Scroll to the cursor.
|
||||||
/// \param how Use this scroll strategy
|
/// \param how Use this scroll strategy
|
||||||
/// \return true if screen was scrolled
|
/// \return true if screen was scrolled
|
||||||
@ -232,7 +231,7 @@ public:
|
|||||||
/// scroll document by the given number of pixels.
|
/// scroll document by the given number of pixels.
|
||||||
int scroll(int 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, bool update);
|
void scrollDocView(int pixels);
|
||||||
/// Set the cursor position based on the scrollbar one.
|
/// Set the cursor position based on the scrollbar one.
|
||||||
void setCursorFromScrollbar();
|
void setCursorFromScrollbar();
|
||||||
|
|
||||||
|
@ -588,7 +588,7 @@ void GuiWorkArea::Private::updateScrollbar()
|
|||||||
void GuiWorkArea::scrollTo(int value)
|
void GuiWorkArea::scrollTo(int value)
|
||||||
{
|
{
|
||||||
stopBlinkingCaret();
|
stopBlinkingCaret();
|
||||||
d->buffer_view_->scrollDocView(value, true);
|
d->buffer_view_->scrollDocView(value);
|
||||||
|
|
||||||
if (lyxrc.cursor_follows_scrollbar) {
|
if (lyxrc.cursor_follows_scrollbar) {
|
||||||
d->buffer_view_->setCursorFromScrollbar();
|
d->buffer_view_->setCursorFromScrollbar();
|
||||||
@ -961,9 +961,9 @@ void GuiWorkArea::generateSyntheticMouseEvent()
|
|||||||
// Scroll
|
// Scroll
|
||||||
if (step <= 2 * wh) {
|
if (step <= 2 * wh) {
|
||||||
d->buffer_view_->scroll(up ? -step : step);
|
d->buffer_view_->scroll(up ? -step : step);
|
||||||
d->buffer_view_->updateMetrics();
|
d->buffer_view_->processUpdateFlags(Update::ForceDraw);
|
||||||
} else {
|
} else {
|
||||||
d->buffer_view_->scrollDocView(value + (up ? -step : step), false);
|
d->buffer_view_->scrollDocView(value + (up ? -step : step));
|
||||||
}
|
}
|
||||||
|
|
||||||
// In which paragraph do we have to set the cursor ?
|
// In which paragraph do we have to set the cursor ?
|
||||||
|
Loading…
Reference in New Issue
Block a user