]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
no need for three calls to update() in a row...
[lyx.git] / src / BufferView_pimpl.C
index 61d686b090556aa4faf4da2ef8a64d4cff4b0e4f..799e8f203b9b2746854836c2daaa9ce413e1cf34 100644 (file)
@@ -313,7 +313,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                        resizeCurrentBuffer();
 
                // FIXME: needed when ?
-               top_y(screen().topCursorVisible(bv_->text));
+               fitCursor();
 
                // Buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
@@ -343,42 +343,11 @@ void BufferView::Pimpl::buffer(Buffer * b)
 bool BufferView::Pimpl::fitCursor()
 {
        lyxerr << "BufferView::Pimpl::fitCursor." << endl;
-
-       int x,y;
-       bv_->cursor().getPos(x, y);
-
-       if (y < top_y() || y > top_y() + workarea().workHeight()) {
-               int newtop = y - workarea().workHeight() / 2;
-               newtop = std::max(0, newtop);
-               top_y(newtop);
+       if (screen().fitCursor(bv_)) {
                updateScrollbar();
                return true;
        }
        return false;
-
-// dead code below
-       bool ret;
-#if 0  
-       UpdatableInset * tli =
-               static_cast<UpdatableInset *>(cursor_.innerInset());
-       if (tli) {
-               tli->fitInsetCursor(bv_);
-               ret = true;
-       } else {
-               ret = screen().fitCursor(bv_->text, bv_);
-       }
-#endif
-#if 0
-       ret = screen().fitCursor(bv_->text, bv_);
-#endif
-
-       //dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
-
-       // We need to always update, in case we did a
-       // paste and we stayed anchored to a row, but
-       // the actual height of the doc changed ...
-       updateScrollbar();
-       return ret;
 }
 
 
@@ -389,7 +358,6 @@ void BufferView::Pimpl::redoCurrentBuffer()
                resizeCurrentBuffer();
                updateScrollbar();
                owner_->updateLayoutChoice();
-               update();
        }
 }
 
@@ -446,7 +414,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                }
        }
 
-       top_y(screen().topCursorVisible(bv_->text));
+       fitCursor();
 
        switchKeyMap();
        owner_->busy(false);
@@ -704,7 +672,6 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        bv_->text->setCursor(par.pit(),
                             min(par->size(), saved_positions[i].par_pos));
 
-       update();
        if (i > 0)
                owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
 }
@@ -750,7 +717,6 @@ void BufferView::Pimpl::center()
        // updateScrollbar() currently. Never mind that this is a
        // pretty obfuscated way of updating t->top_y()
        top_y(new_y);
-       update();
 }
 
 
@@ -879,8 +845,6 @@ void BufferView::Pimpl::trackChanges()
                update();
                bv_->text->setCursor(0, 0);
 #warning changes FIXME
-               //moveCursorUpdate(false);
-
                bool found = lyx::find::findNextChange(bv_);
                if (found) {
                        owner_->getDialogs().show("changes");
@@ -973,8 +937,8 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                                        theTempCursor.pop();
                                        bv_->cursor() = theTempCursor;
                                        bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, top_y() + cmd.y);
-                                       bv_->cursor().updatePos();
-                                       bv_->fitCursor();
+                                       if (bv_->fitCursor())
+                                               bv_->update();
                                        return true;
                                default:
                                        lyxerr << "not dispatched by inner inset val: " << res.val() << endl;
@@ -984,24 +948,26 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
 
                // otherwise set cursor to surrounding LyXText
                if (!res.dispatched()) {
-                       lyxerr << "cursor is: " << bv_->cursor() << endl;
+                       lyxerr << "temp cursor is: " << theTempCursor << endl;
                        lyxerr << "dispatching " << cmd1
                               << " to surrounding LyXText "
-                              << bv_->cursor().innerText() << endl;
+                              << theTempCursor.innerText() << endl;
                        bv_->cursor() = theTempCursor;
-                       theTempCursor.dispatch(cmd1);
-                       bv_->update();
-                       bv_->cursor().updatePos();
+                       res = bv_->cursor().innerText()->dispatch(cmd1);
+                       if (bv_->fitCursor() || res.update())
+                               bv_->update();
+                       
                        //return DispatchResult(true, true);
                }
                // see workAreaKeyPress
                cursor_timeout.restart();
                screen().showCursor(*bv_);
 
-               // FIXME: we should skip these when selecting
-               owner_->updateLayoutChoice();
-               owner_->updateToolbar();
-//             fitCursor();
+               // skip these when selecting
+               if (cmd.action != LFUN_MOUSE_MOTION) {
+                       owner_->updateLayoutChoice();
+                       owner_->updateToolbar();
+               }
 
                // slight hack: this is only called currently when we
                // clicked somewhere, so we force through the display
@@ -1212,11 +1178,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_ACCEPT_ALL_CHANGES: {
                bv_->text->setCursor(0, 0);
 #warning FIXME changes
-               //moveCursorUpdate(false);
-
                while (lyx::find::findNextChange(bv_))
                        bv_->getLyXText()->acceptChange();
-
                update();
                break;
        }
@@ -1224,11 +1187,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_REJECT_ALL_CHANGES: {
                bv_->text->setCursor(0, 0);
 #warning FIXME changes
-               //moveCursorUpdate(false);
-
                while (lyx::find::findNextChange(bv_))
                        bv_->getLyXText()->rejectChange();
-
                update();
                break;
        }
@@ -1295,10 +1255,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
                                   string(),
                                   0);
        }
-
        bv_->cursor().innerText()->insertInset(inset);
-       update();
-
        unFreezeUndo();
        return true;
 }