Abdelrazak Younes wrote:
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.
I forgot the fix for the persistent bits. Here's an updated patch.
Warnings: it won't work perfectly for multiple views and it won't work
nicely when pasting from another Buffer. In copySelectionToStack(Cursor
& cur), instead of passing the BufferView cursor, we could as well
lookup on the different views to find which BufferView has the most
recent selection. But I think the feature is as good as possible now. In
my MVC branch this would be very easy to implement.
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)
@@ -1054,20 +1054,19 @@
// We do this here as if the selection was inside an inset
// 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();
- paste_internally = true;
- }
+ cap::copySelectionToStack(bv->cursor());
// Insert primary selection with middle mouse
// if there is a local selection in the current buffer,
// insert this
if (cmd.button() == mouse_button::button2) {
- if (paste_internally) {
+ if (cap::selection()) {
cap::pasteSelection(cur,
bv->buffer()->errorList("Paste"));
bv->buffer()->errors("Paste");
cur.clearSelection(); // bug 393