Hi,

Following our middle-mouse pasting discussions, I think I've implemented the optimal solution that will work under Mac and Windows too (internally to LyX). My solution is to save the selectionBuffer just before it is pasted in the same LFUN_MOUSE_PRESS. The big change is that we check if the current BufferView cursor has a selection instead of testing if there the selection buffer is not empty (via cap::selection()). This way, cap::selectionBuffer always contain the last selected text.

Please test because I am not sure this will work correctly when pasting external selection under X11.

Abdel.
Index: CutAndPaste.cpp
===================================================================
--- CutAndPaste.cpp     (revision 18982)
+++ CutAndPaste.cpp     (working copy)
@@ -641,8 +641,10 @@
 }
 
 
-void copySelectionToStack()
+void copySelectionToStack(Cursor & cur)
 {
+       copySelectionToStack(cur, selectionBuffer);
+
        if (!selectionBuffer.empty())
                theCuts.push(selectionBuffer[0]);
 }
Index: CutAndPaste.h
===================================================================
--- CutAndPaste.h       (revision 18982)
+++ CutAndPaste.h       (working copy)
@@ -68,7 +68,7 @@
  */
 void copySelection(Cursor & cur, docstring const & plaintext);
 /// Push the selection buffer to the cut buffer.
-void copySelectionToStack();
+void copySelectionToStack(Cursor & cur);
 /// Store the current selection in the internal selection buffer
 void saveSelection(Cursor & cur);
 /// Is a selection available in our selection buffer?
Index: insets/InsetTabular.cpp
===================================================================
--- insets/InsetTabular.cpp     (revision 18982)
+++ insets/InsetTabular.cpp     (working copy)
@@ -3205,12 +3205,12 @@
                }
 
                if (cmd.button() == mouse_button::button2) {
-                       if (cap::selection()) {
+                       if (cur.selection()) {
                                // See comment in Text::dispatch why we
                                // do this
                                // FIXME This does not use paste_tabular,
                                // another reason why paste_tabular should go.
-                               cap::copySelectionToStack();
+                               cap::copySelectionToStack(cur);
                                cmd = FuncRequest(LFUN_PASTE, "0");
                        } else {
                                cmd = FuncRequest(LFUN_PRIMARY_SELECTION_PASTE,
Index: mathed/InsetMathNest.cpp
===================================================================
--- mathed/InsetMathNest.cpp    (revision 18982)
+++ mathed/InsetMathNest.cpp    (working copy)
@@ -1167,9 +1167,9 @@
                cur.updateFlags(Update::Decoration | Update::FitCursor | 
cur.result().update());
        } else if (cmd.button() == mouse_button::button2) {
                MathData ar;
-               if (cap::selection()) {
+               if (cur.selection()) {
                        // See comment in Text::dispatch why we do this
-                       cap::copySelectionToStack();
+                       cap::copySelectionToStack(cur);
                        cmd = FuncRequest(LFUN_PASTE, "0");
                        doDispatch(cur, cmd);
                } else
Index: Text3.cpp
===================================================================
--- Text3.cpp   (revision 18982)
+++ Text3.cpp   (working copy)
@@ -1055,11 +1055,13 @@
                // it could get cleared on the unlocking of the inset so
                // we have to check this first
                bool paste_internally = false;
-               if (cmd.button() == mouse_button::button2 && cap::selection()) {
-                       // Copy the selection buffer to the clipboard
-                       // stack, because we want it to appear in the
+               if (cmd.button() == mouse_button::button2 
+                       && bv->cursor().selection()) {
+                       // Copy the current selection to the Selection buffer
+                       // so that it can be used internally. Copy it to the 
clipboard
+                       // stack too, because we want it to appear in the
                        // "Edit->Paste recent" menu.
-                       cap::copySelectionToStack();
+                       cap::copySelectionToStack(bv->cursor());
                        paste_internally = true;
                }
 

Reply via email to