]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
* Layout.cpp (read): fix ObsoletedBy and DependsOn for layout names
[lyx.git] / src / BufferView.cpp
index c886a1ce00cd16bcc2c7d4e878f631688f54544f..42fbc2dbe5a009d447c7bb404551edebf1c2944c 100644 (file)
@@ -149,6 +149,8 @@ void BufferView::setBuffer(Buffer * b)
                            << "[ b = " << b << "]" << endl;
 
        if (buffer_) {
+               // Save the current selection if any
+               cap::saveSelection(cursor_);
                // Save the actual cursor position and anchor inside the
                // buffer so that it can be restored in case we rechange
                // to this buffer later on.
@@ -1347,11 +1349,15 @@ bool BufferView::mouseSetCursor(Cursor & cur)
 {
        BOOST_ASSERT(&cur.bv() == this);
 
+        // this event will clear selection so we save selection for
+       // persistent selection
+       cap::saveSelection(cursor());
+
        // Has the cursor just left the inset?
        bool badcursor = false;
        bool leftinset = (&cursor_.inset() != &cur.inset());
        if (leftinset)
-               badcursor = cursor_.inset().notifyCursorLeaves(cursor_);
+               badcursor = notifyCursorLeaves(cursor_, cur);
 
        // do the dEPM magic if needed
        // FIXME: (1) move this to InsetText::notifyCursorLeaves?
@@ -1399,7 +1405,6 @@ void BufferView::putSelectionAt(DocIterator const & cur,
                        cursor_.setSelection(cursor_, -length);
                } else
                        cursor_.setSelection(cursor_, length);
-               cap::saveSelection(cursor_);
        }
 }
 
@@ -1440,6 +1445,15 @@ void BufferView::updateMetrics(bool singlepar)
                offset_ref_ = 0;
        }
 
+       if (!singlepar) {
+               // Clear out the position cache in case of full screen redraw,
+               coord_cache_.clear();
+       
+               // Clear out paragraph metrics to avoid having invalid metrics
+               // in the cache from paragraphs not relayouted below
+               tm.clear();
+       }
+
        // If the paragraph metrics has changed, we can not
        // use the singlepar optimisation.
        if (singlepar
@@ -1459,10 +1473,6 @@ void BufferView::updateMetrics(bool singlepar)
        if (!singlepar)
                tm.redoParagraph(pit);
 
-       // Clear out the position cache in case of full screen redraw.
-       if (!singlepar)
-               coord_cache_.clear();
-
        int y0 = tm.parMetrics(pit).ascent() - offset_ref_;
 
        // Redo paragraphs above anchor if necessary.