-void BufferView::center()
-{
- d->anchor_ref_ = d->cursor_.bottom().pit();
- d->need_centering_ = true;
+ if (tm.has(bot_pit)) {
+ ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
+ int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_;
+ int ypos = pm.position() + offset;
+ Dimension const & row_dim = d->cursor_.textRow().dimension();
+ if (ypos - row_dim.ascent() < 0)
+ scrollUp(- ypos + row_dim.ascent());
+ else if (ypos + row_dim.descent() > height_)
+ scrollDown(ypos - height_ + row_dim.descent());
+ // else, nothing to do, the cursor is already visible so we just return.
+ return;
+ }
+
+ tm.redoParagraph(bot_pit);
+ ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
+ int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_;
+
+ d->anchor_pit_ = bot_pit;
+ Dimension const & row_dim = d->cursor_.textRow().dimension();
+
+ if (d->anchor_pit_ == 0)
+ d->anchor_ypos_ = offset + pm.ascent();
+ else if (d->anchor_pit_ == max_pit)
+ d->anchor_ypos_ = height_ - offset - row_dim.descent();
+ else
+ d->anchor_ypos_ = defaultRowHeight() * 2 - offset - row_dim.descent();
+
+ updateMetrics();
+ buffer_.changed();