From 1d51120eb45976e8494c3e8b4301aff6a6a02604 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 10 Jul 2007 12:44:19 +0000 Subject: [PATCH] Restore the persistent selection feature (disabled because of bug 3877) 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 | 7 ++++++- src/Cursor.cpp | 4 +++- src/CutAndPaste.cpp | 9 +++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 2c229a1fce..42fbc2dbe5 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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_); } } diff --git a/src/Cursor.cpp b/src/Cursor.cpp index a603ed2a19..929b4b9230 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -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; } diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index d4af4f1e45..87d0dee691 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -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; }