mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-08 18:19:42 +00:00
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
This commit is contained in:
parent
1db3eb2113
commit
81e06f7bc9
@ -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();
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user