mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
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:
parent
4ec167330f
commit
e207b0250f
@ -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)
|
void BufferView::draw(frontend::Painter & pain)
|
||||||
{
|
{
|
||||||
if (height_ == 0 || width_ == 0)
|
if (height_ == 0 || width_ == 0)
|
||||||
|
@ -261,6 +261,10 @@ public:
|
|||||||
Point getPos(DocIterator const & dit, bool boundary) const;
|
Point getPos(DocIterator const & dit, bool boundary) const;
|
||||||
/// is the paragraph of the cursor visible ?
|
/// is the paragraph of the cursor visible ?
|
||||||
bool paragraphVisible(DocIterator const & dit) const;
|
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;
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -517,8 +517,13 @@ void GuiWorkArea::resizeBufferView()
|
|||||||
// WARNING: Please don't put any code that will trigger a repaint here!
|
// WARNING: Please don't put any code that will trigger a repaint here!
|
||||||
// We are already inside a paint event.
|
// We are already inside a paint event.
|
||||||
lyx_view_->setBusy(true);
|
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_->resize(viewport()->width(), viewport()->height());
|
||||||
buffer_view_->scrollToCursor();
|
if (cursor_in_view)
|
||||||
|
buffer_view_->scrollToCursor();
|
||||||
updateScreen();
|
updateScreen();
|
||||||
|
|
||||||
// Update scrollbars which might have changed due different
|
// Update scrollbars which might have changed due different
|
||||||
@ -552,31 +557,18 @@ void GuiWorkArea::showCursor()
|
|||||||
if (realfont.language() == latex_language)
|
if (realfont.language() == latex_language)
|
||||||
l_shape = false;
|
l_shape = false;
|
||||||
|
|
||||||
Font const font = buffer_view_->cursor().getFont();
|
Point p;
|
||||||
FontMetrics const & fm = theFontMetrics(font);
|
int h = 0;
|
||||||
int const asc = fm.maxAscent();
|
buffer_view_->cursorPosAndHeight(p, h);
|
||||||
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;
|
|
||||||
|
|
||||||
// show cursor on screen
|
// show cursor on screen
|
||||||
|
Cursor & cur = buffer_view_->cursor();
|
||||||
bool completable = cur.inset().showCompletionCursor()
|
bool completable = cur.inset().showCompletionCursor()
|
||||||
&& completer_->completionAvailable()
|
&& completer_->completionAvailable()
|
||||||
&& !completer_->popupVisible()
|
&& !completer_->popupVisible()
|
||||||
&& !completer_->inlineVisible();
|
&& !completer_->inlineVisible();
|
||||||
if (cursorInView) {
|
if (buffer_view_->cursorInView(p, h)) {
|
||||||
cursor_visible_ = true;
|
cursor_visible_ = true;
|
||||||
showCursor(x, y, h, l_shape, isrtl, completable);
|
showCursor(p.x_, p.y_, h, l_shape, isrtl, completable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user