]> git.lyx.org Git - features.git/commitdiff
Make sure that the document is only scrolled to the cursor when the cursor is/was...
authorVincent van Ravesteijn <vfr@lyx.org>
Fri, 3 Apr 2009 21:39:06 +0000 (21:39 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Fri, 3 Apr 2009 21:39:06 +0000 (21:39 +0000)
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

src/BufferView.cpp
src/BufferView.h
src/frontends/qt4/GuiWorkArea.cpp

index 53cd4d09a89ad9cf963c2d0dca41980f9b0d373d..c75b115fadc9891fb17f33d9d021fdec965c737c 100644 (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)
index 0105275eae1713218550af1e1aace7e7c08ef470..b5de004c3d69a43184f0d57d84c712d71a3ec626 100644 (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;
 
 
        ///
index 29789c7a25c8b7a43cf2241a9b824c120f706ac1..344b63044cda63b3a47c22171b9817c4a17dd7b0 100644 (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);
        }
 }