>>>>> "Abdelrazak" == Abdelrazak Younes <[EMAIL PROTECTED]> writes:
Abdelrazak> The patch is shorter yes but I don't think the final code Abdelrazak> will be shorter. No, but it is less complex IMO. >> 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). Abdelrazak> Why don't you just passed cur.bv().cursor()? The code says: I do something at 'cur', and saveselection looks whether that matters. This seems more robust to me. >> AFAIK, Bo's code does not work with multiple windows (where no >> buffer-switch happens). Abdelrazak> Why is that? IIRC he saves the selection in Abdelrazak> LyXFunc::setLyXView(). I stand corrected (and the code is already in). The following version of my patch saves selection in BufferView::setBuffer, thus handling buffer-switch. But since I look where stuff really happens, this handle the case of buffer-next/previous (ctrl-page up/down), which Bo missed. Besides the fact that adding the SaveSelection flag is easy, I guess you can see why this is error prone... Also, I removed a saveSelection in BufferView::putSelectionAt. I think it is a remnant of the old code. JMarc PS: concerning Bo's patch, I _think_ it should be possible to put the test for clearselection in LyXFunc::dispatch, instead of copying it in 3 different places.
Index: src/BufferView.cpp =================================================================== --- src/BufferView.cpp (révision 19007) +++ src/BufferView.cpp (copie de travail) @@ -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 & { 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(DocItera cursor_.setSelection(cursor_, -length); } else cursor_.setSelection(cursor_, length); - cap::saveSelection(cursor_); } } 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;