>>>>> "Bo" == Bo Peng <[EMAIL PROTECTED]> writes:

>> Concerning your approach, many things are still missing (IMO of
>> course). For example, self-insert will replace the selection if
>> there is one, so you should save the selection.

Bo> This is expected, and can be solved easily by adding SaveSelection
Bo> flag to this LFUN. The advantage of my patch is that I can handle
Bo> all these cases in a uniform way, in a single file
Bo> (LyXAction.cpp).

OTOH, in my approach I try to put the calls at the place where the
selection is actually lost, which makes the code simpler to
understand. (and shall I say shorter?)

BTW, the entries for paragraph-move-up/down seem bogus to me (isn't it
disabled when there is a selection)?

>> Tracking all the lfuns where this happens is more complicated IMO
>> than adding a proper call in eraseSelection and cutSelection (patch
>> coming).

Here is what I came up with. Note that now saveSelection does its job
only if cursor is actually bv.cursor() (to make Abdel happy). 

The changes in Text3.cpp should go in anyway, I think. The
semantics of the LFUNS with a selection was bad. 

The only known issue now is that I do not handle BUFFER_SWITCH. It is
not that I cannot add one line in an LFUN, but I'd like first to
understand what the policy is: can we have several selections active
different bufferviews? AFAIK, Bo's code does not work with multiple
windows (where no buffer-switch happens). Therefore the solution has
to be different.

As you said, it is up to Jose' to decide.

JMarc

Index: src/BufferView.cpp
===================================================================
--- src/BufferView.cpp	(révision 19007)
+++ src/BufferView.cpp	(copie de travail)
@@ -1347,6 +1347,10 @@ bool BufferView::mouseSetCursor(Cursor &
 {
 	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());
Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp	(révision 19007)
+++ src/CutAndPaste.cpp	(copie de travail)
@@ -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"
@@ -524,6 +525,8 @@ void cutSelection(Cursor & cur, bool doc
 		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();
@@ -674,7 +677,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;
@@ -830,6 +835,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());
@@ -850,7 +856,6 @@ void eraseSelection(Cursor & cur)
 		}
 		// need a valid cursor. (Lgb)
 		cur.clearSelection();
-		theSelection().haveSelection(false);
 	} else {
 		lyxerr << "can't erase this selection 1" << endl;
 	}
Index: src/Cursor.cpp
===================================================================
--- src/Cursor.cpp	(révision 19007)
+++ src/Cursor.cpp	(copie de travail)
@@ -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: src/Text3.cpp
===================================================================
--- src/Text3.cpp	(révision 19007)
+++ src/Text3.cpp	(copie de travail)
@@ -436,20 +436,26 @@ void Text::dispatch(Cursor & cur, FuncRe
 	}
 
 	case LFUN_WORD_DELETE_FORWARD:
-		cur.clearSelection();
-		deleteWordForward(cur);
+		if (cur.selection()) {
+			cutSelection(cur, true, false);
+		} else
+			deleteWordForward(cur);
 		finishChange(cur, false);
 		break;
 
 	case LFUN_WORD_DELETE_BACKWARD:
-		cur.clearSelection();
-		deleteWordBackward(cur);
+		if (cur.selection()) {
+			cutSelection(cur, true, false);
+		} else
+			deleteWordBackward(cur);
 		finishChange(cur, false);
 		break;
 
 	case LFUN_LINE_DELETE:
-		cur.clearSelection();
-		deleteLineForward(cur);
+		if (cur.selection()) {
+			cutSelection(cur, true, false);
+		} else
+			deleteLineForward(cur);
 		finishChange(cur, false);
 		break;
 

Reply via email to