}
+void BufferView::recenter()
+{
+ showCursor(d->cursor_, true);
+}
+
+
void BufferView::showCursor()
{
- showCursor(d->cursor_);
+ showCursor(d->cursor_, false);
}
-void BufferView::showCursor(DocIterator const & dit)
+void BufferView::showCursor(DocIterator const & dit, bool recenter)
{
// We are not properly started yet, delay until resizing is
// done.
Dimension const & row_dim =
pm.getRow(cs.pos(), dit.boundary()).dimension();
int scrolled = 0;
- if (ypos - row_dim.ascent() < 0)
+ if (recenter)
+ scrolled = scroll(ypos - height_/2);
+ else if (ypos - row_dim.ascent() < 0)
scrolled = scrollUp(- ypos + row_dim.ascent());
else if (ypos + row_dim.descent() > height_)
scrolled = scrollDown(ypos - height_ + defaultRowHeight() );
Dimension const & row_dim =
pm.getRow(cs.pos(), dit.boundary()).dimension();
- if (d->anchor_pit_ == 0)
+ if (recenter)
+ d->anchor_ypos_ = height_/2;
+ else 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();
case LFUN_MARK_ON:
case LFUN_MARK_TOGGLE:
case LFUN_SCREEN_RECENTER:
+ case LFUN_SCREEN_SHOW_CURSOR:
case LFUN_BIBTEX_DATABASE_ADD:
case LFUN_BIBTEX_DATABASE_DEL:
case LFUN_NOTES_MUTATE:
cur.resetAnchor();
break;
- case LFUN_SCREEN_RECENTER:
+ case LFUN_SCREEN_SHOW_CURSOR:
showCursor();
break;
+
+ case LFUN_SCREEN_RECENTER:
+ recenter();
+ break;
case LFUN_BIBTEX_DATABASE_ADD: {
Cursor tmpcur = d->cursor_;
/// set cursor to the given inset. Return true if found.
bool setCursorFromInset(Inset const *);
-
+ /// Recenters the BufferView such that the passed cursor
+ /// is in the center.
+ void recenter();
/// Ensure that the BufferView cursor is visible.
/// This method will automatically scroll and update the BufferView
/// if needed.
- void showCursor();
+ 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);
+ /// \param recenter Whether the cursor should be centered on screen
+ void showCursor(DocIterator const & dit, bool recenter = false);
/// LFUN_SCROLL Helper.
void lfunScroll(FuncRequest const & cmd);
/// scroll down document by the given number of pixels.
LFUN_INSET_END, // JMarc, 20090316
LFUN_INSET_BEGIN_SELECT, // JMarc, 20090316
LFUN_INSET_END_SELECT, // JMarc, 20090316
+ LFUN_SCREEN_SHOW_CURSOR, // vfr, 20090325
LFUN_LASTACTION // end of the table
*/
{ LFUN_SCREEN_RECENTER, "screen-recenter", ReadOnly, Edit },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_SCREEN_SHOW_CURSOR
+ * \li Action: Repositions the screen such that the cursor is visible.
+ * \li Syntax: screen-show-cursor
+ * \endvar
+ */
+ { LFUN_SCREEN_SHOW_CURSOR, "screen-show-cursor", ReadOnly, Edit },
+
/*!
* \var lyx::FuncCode lyx::LFUN_CHAR_BACKWARD
* \li Action: Moves the cursor one position logically backwards.
BufferView * bv = &cur.bv();
TextMetrics & tm = bv->textMetrics(this);
if (!tm.contains(cur.pit())) {
- lyx::dispatch(FuncRequest(LFUN_SCREEN_RECENTER));
+ lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
tm = bv->textMetrics(this);
}