]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
latex_lang should not have a babel language
[lyx.git] / src / BufferView.cpp
index 2c229a1fce5e9d812bd9c196c6c1d41504337613..390b62e01d88a96a02455291e8caea33bbb50c34 100644 (file)
 #include <functional>
 #include <vector>
 
+using std::distance;
+using std::endl;
+using std::istringstream;
+using std::make_pair;
+using std::min;
+using std::max;
+using std::mem_fun_ref;
+using std::string;
+using std::vector;
+
 
 namespace lyx {
 
@@ -91,16 +101,6 @@ using support::isFileReadable;
 using support::makeDisplayPath;
 using support::package;
 
-using std::distance;
-using std::endl;
-using std::istringstream;
-using std::make_pair;
-using std::min;
-using std::max;
-using std::mem_fun_ref;
-using std::string;
-using std::vector;
-
 namespace Alert = frontend::Alert;
 
 namespace {
@@ -143,12 +143,14 @@ Buffer * BufferView::buffer() const
 }
 
 
-void BufferView::setBuffer(Buffer * b)
+Buffer * BufferView::setBuffer(Buffer * b)
 {
        LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION
                            << "[ 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.
@@ -180,7 +182,7 @@ void BufferView::setBuffer(Buffer * b)
        // If we're quitting lyx, don't bother updating stuff
        if (quitting) {
                buffer_ = 0;
-               return;
+               return 0;
        }
 
        //FIXME Fix for bug 3440 is here.
@@ -207,7 +209,7 @@ void BufferView::setBuffer(Buffer * b)
        offset_ref_ = 0;
 
        if (!buffer_)
-               return;
+               return 0;
 
        LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION
                                        << "Buffer addr: " << buffer_ << endl;
@@ -241,6 +243,7 @@ void BufferView::setBuffer(Buffer * b)
 
        if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
                graphics::Previews::get().generateBufferPreviews(*buffer_);
+       return buffer_;
 }
 
 
@@ -1257,6 +1260,7 @@ void BufferView::setCursorFromRow(int row)
 
        buffer_->texrow().getIdFromRow(row, tmpid, tmppos);
 
+       cursor_.reset(buffer_->inset());
        if (tmpid == -1)
                buffer_->text().setCursor(cursor_, 0, 0);
        else
@@ -1347,6 +1351,10 @@ 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());
@@ -1399,7 +1407,6 @@ void BufferView::putSelectionAt(DocIterator const & cur,
                        cursor_.setSelection(cursor_, -length);
                } else
                        cursor_.setSelection(cursor_, length);
-               cap::saveSelection(cursor_);
        }
 }