]> git.lyx.org Git - lyx.git/commitdiff
Restore the persistent selection feature (disabled because of bug 3877)
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 10 Jul 2007 12:44:19 +0000 (12:44 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 10 Jul 2007 12:44:19 +0000 (12:44 +0000)
See also http://www.lyx.org/trac/changeset/19003

* BufferView.cpp (setBuffer): save selection before switching buffer
(mouseSetCursor): save selection before resetting it
(putSelectionAt): no need to save selection

* Cursor.cpp (selHandle): save selection before resetting it

* CutAndPaste.cpp (cutSelection, eraseSelection): save selection before
deleting it.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19026 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/Cursor.cpp
src/CutAndPaste.cpp

index 2c229a1fce5e9d812bd9c196c6c1d41504337613..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,6 +1349,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 +1405,6 @@ void BufferView::putSelectionAt(DocIterator const & cur,
                        cursor_.setSelection(cursor_, -length);
                } else
                        cursor_.setSelection(cursor_, length);
-               cap::saveSelection(cursor_);
        }
 }
 
index a603ed2a19a7c1352d48fcd91510b6fb799a9bc5..929b4b9230d70e65e9899ecf1f3aa7c69b346727 100644 (file)
@@ -588,9 +588,11 @@ bool Cursor::selHandle(bool sel)
        if (sel == selection())
                return false;
 
+       if (!sel)
+               cap::saveSelection(*this);
+
        resetAnchor();
        selection() = sel;
-       cap::saveSelection(*this);
        return true;
 }
 
index d4af4f1e4595153ad48f3666170ef77294ed819c..87d0dee691c22439f43fc95b7ce02fd65ccc42ab 100644 (file)
@@ -18,6 +18,7 @@
 #include "Buffer.h"
 #include "buffer_funcs.h"
 #include "BufferParams.h"
+#include "BufferView.h"
 #include "Cursor.h"
 #include "debug.h"
 #include "ErrorList.h"
@@ -526,6 +527,8 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
                Text * text = cur.text();
                BOOST_ASSERT(text);
 
+               saveSelection(cur);
+
                // make sure that the depth behind the selection are restored, too
                recordUndoSelection(cur);
                pit_type begpit = cur.selBegin().pit();
@@ -676,7 +679,9 @@ void saveSelection(Cursor & cur)
        // This function is called, not when a selection is formed, but when
        // a selection is cleared. Therefore, multiple keyboard selection
        // will not repeatively trigger this function (bug 3877).
-       if (cur.selection()) {
+       if (cur.selection() 
+           && cur.selBegin() == cur.bv().cursor().selBegin()
+           && cur.selEnd() == cur.bv().cursor().selEnd()) {
                LYXERR(Debug::ACTION) << BOOST_CURRENT_FUNCTION << ": `"
                           << to_utf8(cur.selectionAsString(true)) << "'."
                           << endl;
@@ -832,6 +837,7 @@ void eraseSelection(Cursor & cur)
        CursorSlice const & i1 = cur.selBegin();
        CursorSlice const & i2 = cur.selEnd();
        if (i1.inset().asInsetMath()) {
+               saveSelection(cur);
                cur.top() = i1;
                if (i1.idx() == i2.idx()) {
                        i1.cell().erase(i1.pos(), i2.pos());
@@ -852,7 +858,6 @@ void eraseSelection(Cursor & cur)
                }
                // need a valid cursor. (Lgb)
                cur.clearSelection();
-               theSelection().haveSelection(false);
        } else {
                lyxerr << "can't erase this selection 1" << endl;
        }