]> git.lyx.org Git - features.git/commitdiff
Fix bug 5526: screen-recenter LFUN doesn't work
authorVincent van Ravesteijn <vfr@lyx.org>
Thu, 26 Mar 2009 00:09:16 +0000 (00:09 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Thu, 26 Mar 2009 00:09:16 +0000 (00:09 +0000)
http://bugzilla.lyx.org/show_bug.cgi?id=5526

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28916 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h
src/FuncCode.h
src/LyXAction.cpp
src/Text3.cpp

index 67f45d610154014beba5d9f644baea990a1c40bb..fbe30f11e6c83d91a597ad055d5bca9da9b0984d 100644 (file)
@@ -787,13 +787,19 @@ int BufferView::workWidth() const
 }
 
 
+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.
@@ -829,7 +835,9 @@ void BufferView::showCursor(DocIterator const & dit)
                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() ); 
@@ -855,7 +863,9 @@ void BufferView::showCursor(DocIterator const & dit)
        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();
@@ -904,6 +914,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
        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:
@@ -1295,9 +1306,13 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                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_;
index 0f6b55b80ad95e74c42410e336fad9c5c88f0f50..9335a85ab4b22b452847364304d002f62ebd3608 100644 (file)
@@ -146,15 +146,18 @@ public:
 
        /// 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.
index 1d6428a33174b08ad08edcd8ac85356d4a1aee05..f35ed20d3f8109eafc100cd387a1612bffe3d42d 100644 (file)
@@ -423,6 +423,7 @@ enum FuncCode
        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
index 650f3d5692767aac6f0233398fb86e9cc9ac577e..390d8923ea208e8c1795e9a2a8eb5d3d0e2e355e 100644 (file)
@@ -679,6 +679,14 @@ void LyXAction::init()
  */
                { 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.
index 0a84a70f536849ec644a9f3faed55ab0a53c9d2e..cfd8c98e9e272564db169e76cb768ee1cbc25075 100644 (file)
@@ -448,7 +448,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        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);
        }