Make sure that the document is only scrolled to the cursor when the cursor is/was visible before resizing .

Resizing can occur by toggling toolbars (bug 4733), or by creating or closing buffers which causes the tabbar to toggle (e.g. bug 4174, comment 5).



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29066 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-04-03 21:39:06 +00:00
parent 4ec167330f
commit e207b0250f
3 changed files with 39 additions and 20 deletions

View File

@ -2278,6 +2278,29 @@ bool BufferView::paragraphVisible(DocIterator const & dit) const
}
void BufferView::cursorPosAndHeight(Point & p, int & h) const
{
Cursor const & cur = cursor();
Font const font = cur.getFont();
frontend::FontMetrics const & fm = theFontMetrics(font);
int const asc = fm.maxAscent();
int const des = fm.maxDescent();
h = asc + des;
p = getPos(cur, cur.boundary());
p.y_ -= asc;
}
bool BufferView::cursorInView(Point const & p, int h) const
{
Cursor const & cur = cursor();
// does the cursor touch the screen ?
if (p.y_ + h < 0 || p.y_ >= workHeight() || !paragraphVisible(cur))
return false;
return true;
}
void BufferView::draw(frontend::Painter & pain)
{
if (height_ == 0 || width_ == 0)

View File

@ -261,6 +261,10 @@ public:
Point getPos(DocIterator const & dit, bool boundary) const;
/// is the paragraph of the cursor visible ?
bool paragraphVisible(DocIterator const & dit) const;
/// is the cursor currently visible in the view
bool cursorInView(Point const & p, int h) const;
/// get the position and height of the cursor
void cursorPosAndHeight(Point & p, int & h) const;
///

View File

@ -517,8 +517,13 @@ void GuiWorkArea::resizeBufferView()
// WARNING: Please don't put any code that will trigger a repaint here!
// We are already inside a paint event.
lyx_view_->setBusy(true);
Point p;
int h = 0;
buffer_view_->cursorPosAndHeight(p, h);
bool const cursor_in_view = buffer_view_->cursorInView(p, h);
buffer_view_->resize(viewport()->width(), viewport()->height());
buffer_view_->scrollToCursor();
if (cursor_in_view)
buffer_view_->scrollToCursor();
updateScreen();
// Update scrollbars which might have changed due different
@ -552,31 +557,18 @@ void GuiWorkArea::showCursor()
if (realfont.language() == latex_language)
l_shape = false;
Font const font = buffer_view_->cursor().getFont();
FontMetrics const & fm = theFontMetrics(font);
int const asc = fm.maxAscent();
int const des = fm.maxDescent();
int h = asc + des;
int x = 0;
int y = 0;
Cursor & cur = buffer_view_->cursor();
cur.getPos(x, y);
y -= asc;
// if it doesn't touch the screen, don't try to show it
bool cursorInView = true;
if (y + h < 0 || y >= viewport()->height()
|| !cur.bv().paragraphVisible(cur))
cursorInView = false;
Point p;
int h = 0;
buffer_view_->cursorPosAndHeight(p, h);
// show cursor on screen
Cursor & cur = buffer_view_->cursor();
bool completable = cur.inset().showCompletionCursor()
&& completer_->completionAvailable()
&& !completer_->popupVisible()
&& !completer_->inlineVisible();
if (cursorInView) {
if (buffer_view_->cursorInView(p, h)) {
cursor_visible_ = true;
showCursor(x, y, h, l_shape, isrtl, completable);
showCursor(p.x_, p.y_, h, l_shape, isrtl, completable);
}
}