]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
* InsetListings.cpp:
[lyx.git] / src / BufferView.cpp
index 8ce25ec07f46a96f0a9be872445851e6af39185d..5c49a8145a34e29bd306caacd80bf3cb17696fce 100644 (file)
@@ -315,6 +315,9 @@ BufferView::~BufferView()
        fp.pit = d->cursor_.bottom().pit();
        fp.pos = d->cursor_.bottom().pos();
        theSession().lastFilePos().save(buffer_.fileName(), fp);
+       
+       if (d->last_inset_)
+               d->last_inset_->setMouseHover(this, false);     
 
        delete d;
 }
@@ -403,11 +406,6 @@ bool BufferView::fitCursor()
 
 void BufferView::processUpdateFlags(Update::flags flags)
 {
-       // last_inset_ points to the last visited inset. This pointer may become  
-       // invalid because of keyboard editing. Since all such operations  
-       // causes screen update(), I reset last_inset_ to avoid such a problem.  
-       d->last_inset_ = 0;  
-
        // This is close to a hot-path.
        LYXERR(Debug::DEBUG, "BufferView::processUpdateFlags()"
                << "[fitcursor = " << (flags & Update::FitCursor)
@@ -874,10 +872,22 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool recenter)
                int scrolled = 0;
                if (recenter)
                        scrolled = scroll(ypos - height_/2);
+
+               // If the top part of the row falls of the screen, we scroll
+               // up to align the top of the row with the top of the screen.
                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() ); 
+                       scrolled = scrollUp(-ypos + row_dim.ascent());
+
+               // If the bottom of the row falls of the screen, we scroll down.
+               // However, we have to be careful not to scroll that much that
+               // the top falls of the screen.
+               else if (ypos + row_dim.descent() > height_) {
+                       int ynew = height_ - row_dim.descent();
+                       if (ynew < row_dim.ascent())
+                               ynew = row_dim.ascent();
+                       int const scroll = ypos - ynew;
+                       scrolled = scrollDown(scroll);
+               }
 
                // else, nothing to do, the cursor is already visible so we just return.
                return scrolled != 0;
@@ -1068,7 +1078,12 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                flag.setOnOff(buffer_.params().compressed);
                break;
        }
-       
+
+       case LFUN_BUFFER_TOGGLE_OUTPUT_SYNC: {
+               flag.setOnOff(buffer_.params().output_sync);
+               break;
+       }
+
        case LFUN_SCREEN_UP:
        case LFUN_SCREEN_DOWN:
        case LFUN_SCROLL:
@@ -1578,6 +1593,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().compressed = !buffer_.params().compressed;
                break;
 
+       case LFUN_BUFFER_TOGGLE_OUTPUT_SYNC:
+               buffer_.params().output_sync = !buffer_.params().output_sync;
+               break;
+
        case LFUN_SCREEN_UP:
        case LFUN_SCREEN_DOWN: {
                Point p = getPos(cur);
@@ -1888,18 +1907,22 @@ void BufferView::updateHoveredInset() const
                return;
 
        bool need_redraw = false;
-       if (d->last_inset_)
+       if (d->last_inset_) {
                // Remove the hint on the last hovered inset (if any).
-               need_redraw |= d->last_inset_->setMouseHover(false);
+               need_redraw |= d->last_inset_->setMouseHover(this, false);
+               d->last_inset_ = 0;
+       }
        
        // const_cast because of setMouseHover().
        Inset * inset = const_cast<Inset *>(covering_inset);
-       if (inset)
-               // Highlight the newly hovered inset (if any).
-               need_redraw |= inset->setMouseHover(true);
+       if (inset && inset->setMouseHover(this, true)) {
+               need_redraw = true;
+               // Only the insets that accept the hover state, do 
+               // clear the last_inset_, so only set the last_inset_
+               // member if the hovered setting is accepted.
+               d->last_inset_ = inset;
+       }
 
-       d->last_inset_ = inset;
-       
        if (need_redraw) {
                LYXERR(Debug::PAINTING, "Mouse hover detected at: ("
                                << d->mouse_position_cache_.x_ << ", " 
@@ -1914,6 +1937,16 @@ void BufferView::updateHoveredInset() const
 }
 
 
+void BufferView::clearLastInset(Inset * inset) const
+{
+       if (d->last_inset_ != inset) {
+               LYXERR0("Wrong last_inset!");
+               LASSERT(false, /**/);
+       }
+       d->last_inset_ = 0;
+}
+
+
 void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
 {
        //lyxerr << "[ cmd0 " << cmd0 << "]" << endl;