hluk / CopyQ

Clipboard manager with advanced features
GNU General Public License v3.0
8.63k stars 440 forks source link

Copy with mouse - disable with key press needed #2297

Closed francwalter closed 1 year ago

francwalter commented 1 year ago

Hello I like the feature to copy text just by selecting it with the mouse. I like the paste feature (middle mouse press) too, and that I can disable the mouse selected clips for keyboard pasting. But in work flow a thing is missing or I dont know how to handle it:

I want to paste some parts of code into another part of code which should be replaced:

but this wouldnt work, as in the (mouse) clipboard there is now the deleted text. Here I would like to have a key to modify the mouse selection copy feature:

If I press e.g. CTRL when selecting, the mouse does NOT copy text. Would that be possible? I didnt find an extension for it. Thank. frank

Ubuntu 22.04 with CopyQ 6.4.0

PS.: but anyway, CopyQ is fantastic! Really! Great thing to have, very productive! Thank a lot!

hluk commented 1 year ago

If I press e.g. CTRL when selecting, the mouse does NOT copy text.

I like the idea. Often the text selections overriding clipboard is unexpected.

It won't work in Wayland (it does not support checking currently pressed keyboard modifiers), but elsewhere the following command should handle this. It reverts last to the selection and avoid synchronizing to clipboard if the Ctrl is pressed while selecting the text (here is how to add the command to CopyQ):

[Command]
Command="
    function selectWithoutCopy()
    {
        return queryKeyboardModifiers().includes('Ctrl')
    }

    function reset(key, setFn) {
        var last = settings(key);
        if (last && last[1] == settings(key)[1]) {
            serverLog('Reset from ' + key);
            popup('Ready to paste ' + key, last[0]);
            setFn(mimeText, last[0], mimeHidden, 1);
        }
    }

    function save(key) {
        if (hasData()) {
            settings(key, [data(mimeText), Date.now()]);
        }
    }

    function resetClipboard() {
        return reset('lastClipboard', clipboard, copy);
    }

    function resetSelection() {
        return reset('lastSelection', selection, copySelection);
    }

    var onClipboardChanged_ = onClipboardChanged;
    onClipboardChanged = function() {
        if (!isClipboard() && selectWithoutCopy()) {
            resetClipboard();
            resetSelection();
            return;
        }

        onClipboardChanged_();

        if (isClipboard()) {
            save('lastClipboard');
        } else {
            save('lastSelection');
        }
    }

    var synchronizeFromSelection_ = synchronizeFromSelection;
    synchronizeFromSelection = function() {
        if (!selectWithoutCopy()) {
            synchronizeFromSelection_();
        }
    }"
Icon=\xf246
IsScript=true
Name=Avoid overriding selection with CTRL
francwalter commented 1 year ago

GREAT! Thanks, that works :) I am on Ubuntu 22.04 with Gnome and I just looked, I have Wayland disabled, but I didnt do that. In: /etc/gdm3/custom.conf I read: WaylandEnable=false and I am pretty sure, that I did not disable it. Must be by default or some installing, dont know. Strange. When I look into the file properties, I see this was on install date (I installed Ubuntu on 21.02.2023):

-rw-r--r--   1 root root  540 Feb 22 11:08 custom.conf
-rw-r--r--   1 root root  541 Feb 21 22:49 custom.conf.bak

The conf.bak has the WaylandEnable=false commented out. Anyway, it works with CTRL (without Wayland) which is of good help, THANK a lot! frank