]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Partially revert r34995, which broke math output. Not sure why yet....
[lyx.git] / src / BufferView.cpp
index 0a4e11bcb1c85ee91f38800ae5e52f0b79c97b07..076bff7af85021370adc4487d92167dd71ae189e 100644 (file)
@@ -221,7 +221,7 @@ struct BufferView::Private
                anchor_pit_(0), anchor_ypos_(0),
                inlineCompletionUniqueChars_(0),
                last_inset_(0), mouse_position_cache_(),
-               bookmark_edit_position_(0), gui_(0)
+               bookmark_edit_position_(-1), gui_(0)
        {}
 
        ///
@@ -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)
@@ -415,6 +413,8 @@ void BufferView::processUpdateFlags(Update::flags flags)
                << ", singlepar = " << (flags & Update::SinglePar)
                << "]  buffer: " << &buffer_);
 
+       // FIXME Does this really need doing here? It's done in updateBuffer, and
+       // if the Buffer doesn't need updating, then do the macros?
        buffer_.updateMacros();
 
        // Now do the first drawing step if needed. This consists on updating
@@ -570,7 +570,7 @@ docstring BufferView::contextMenu(int x, int y) const
 }
 
 
-void BufferView::scrollDocView(int value)
+void BufferView::scrollDocView(int value, bool update)
 {
        int const offset = value - d->scrollbarParameters_.position;
 
@@ -589,7 +589,7 @@ void BufferView::scrollDocView(int value)
        // cut off at the top
        if (value <= d->scrollbarParameters_.min) {
                DocIterator dit = doc_iterator_begin(&buffer_);
-               showCursor(dit);
+               showCursor(dit, false, update);
                LYXERR(Debug::SCROLLING, "scroll to top");
                return;
        }
@@ -598,7 +598,7 @@ void BufferView::scrollDocView(int value)
        if (value >= d->scrollbarParameters_.max) {
                DocIterator dit = doc_iterator_end(&buffer_);
                dit.backwardPos();
-               showCursor(dit);
+               showCursor(dit, false, update);
                LYXERR(Debug::SCROLLING, "scroll to bottom");
                return;
        }
@@ -616,14 +616,14 @@ void BufferView::scrollDocView(int value)
                // It seems we didn't find the correct pit so stay on the safe side and
                // scroll to bottom.
                LYXERR0("scrolling position not found!");
-               scrollDocView(d->scrollbarParameters_.max);
+               scrollDocView(d->scrollbarParameters_.max, update);
                return;
        }
 
        DocIterator dit = doc_iterator_begin(&buffer_);
        dit.pit() = i;
        LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
-       showCursor(dit);
+       showCursor(dit, false, update);
 }
 
 
@@ -808,19 +808,20 @@ int BufferView::workWidth() const
 
 void BufferView::recenter()
 {
-       showCursor(d->cursor_, true);
+       showCursor(d->cursor_, true, true);
 }
 
 
 void BufferView::showCursor()
 {
-       showCursor(d->cursor_, false);
+       showCursor(d->cursor_, false, true);
 }
 
 
-void BufferView::showCursor(DocIterator const & dit, bool recenter)
+void BufferView::showCursor(DocIterator const & dit,
+       bool recenter, bool update)
 {
-       if (scrollToCursor(dit, recenter)) {
+       if (scrollToCursor(dit, recenter) && update) {
                buffer_.changed(true);
                updateHoveredInset();
        }
@@ -936,7 +937,6 @@ void BufferView::updateDocumentClass(DocumentClass const * const olddc)
        setCursor(backcur.asDocIterator(&buffer_));
 
        buffer_.errors("Class Switch");
-       buffer_.updateBuffer();
 }
 
 /** Return the change status at cursor position, taking in account the
@@ -1080,7 +1080,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:
@@ -1199,6 +1204,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                // It is then better to make sure that all dialogs are in sync with
                // current document settings.
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
                
@@ -1210,6 +1216,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1227,6 +1234,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1250,6 +1258,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldDocClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1266,6 +1275,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1276,6 +1286,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dr.setMessage(_("No further undo information"));
                else
                        dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_REDO:
@@ -1285,6 +1296,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dr.setMessage(_("No further redo information"));
                else
                        dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_FONT_STATE:
@@ -1398,6 +1410,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        case LFUN_CHANGES_MERGE:
                if (findNextChange(this) || findPreviousChange(this)) {
                        dr.update(Update::Force | Update::FitCursor);
+                       dr.forceBufferUpdate();
                        showDialog("changes");
                }
                break;
@@ -1411,6 +1424,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_ALL_CHANGES_REJECT:
@@ -1423,6 +1437,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.text().acceptOrRejectChanges(cur, Text::REJECT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_WORD_FIND_FORWARD:
@@ -1477,6 +1492,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        }
                }
                replace(this, cmd, has_deleted);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1590,6 +1606,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);
@@ -1617,13 +1637,16 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                //FIXME: what to do with cur.x_target()?
                bool update = in_texted && cur.bv().checkDepm(cur, old);
                cur.finishUndo();
-               if (update)
+               if (update) {
                        dr.update(Update::Force | Update::FitCursor);
+                       dr.forceBufferUpdate();
+               }
                break;
        }
 
        case LFUN_SCROLL:
                lfunScroll(cmd);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_SCREEN_UP_SELECT: {
@@ -1700,6 +1723,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                cur = savecur;
                cur.fixIfBroken();
                dr.update(Update::Force);
+               dr.forceBufferUpdate();
 
                if (iterations >= max_iter) {
                        dr.setError(true);
@@ -1723,7 +1747,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        Alert::warning(_("Branch already exists"), drtmp.message());
                        break;
                }
-               lyx::dispatch(FuncRequest(LFUN_BRANCH_INSERT, branch_name));
+               BranchList & branch_list = buffer_.params().branchlist();
+               vector<docstring> const branches =
+                       getVectorFromString(branch_name, branch_list.separator());
+               for (vector<docstring>::const_iterator it = branches.begin();
+                    it != branches.end(); ++it) {
+                       branch_name = *it;
+                       lyx::dispatch(FuncRequest(LFUN_BRANCH_INSERT, branch_name));
+               }
                break;
        }
 
@@ -1795,6 +1826,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
                inset->dispatch(cur, fr);
                dr.update(Update::SinglePar | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1900,18 +1932,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(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(this, 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_ << ", " 
@@ -1926,6 +1962,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;
@@ -2198,7 +2244,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old)
 
        d->cursor_ = cur;
 
-       buffer_.updateBuffer();
+       cur.forceBufferUpdate();
        buffer_.changed(true);
        return true;
 }
@@ -2242,6 +2288,8 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
 
        d->cursor_.finishUndo();
        d->cursor_.setCurrentFont();
+       if (update)
+               cur.forceBufferUpdate();
        return update;
 }
 
@@ -2803,9 +2851,9 @@ void BufferView::setInlineCompletion(Cursor & cur, DocIterator const & pos,
        // set update flags
        if (changed) {
                if (singlePar && !(cur.result().update() & Update::Force))
-                       cur.updateFlags(cur.result().update() | Update::SinglePar);
+                       cur.screenUpdateFlags(cur.result().update() | Update::SinglePar);
                else
-                       cur.updateFlags(cur.result().update() | Update::Force);
+                       cur.screenUpdateFlags(cur.result().update() | Update::Force);
        }
 }