hluk / copyq-commands

Useful commands for CopyQ clipboard manager.
331 stars 73 forks source link

Update 'move-images-to-other-tab' command #34

Closed moritzdietz closed 3 years ago

moritzdietz commented 3 years ago

This PR updates the move-images-to-other-tab.ini command so that it matches all MIME types of image/ instead of only matching image/png.

This was previously discussed here https://github.com/hluk/CopyQ/discussions/1536#discussioncomment-193452. This PR is ready for review.

moritzdietz commented 3 years ago

I did find a bug with this command though! When you try it out, images are indeed moved out of the clipboard tab and moved into the Images, but normal text get's moved there as well.

Could this possibly be an issue? Or is this "overridden" from inside the command and not displayed in the GUI? image

hluk commented 3 years ago

I did find a bug with this command though! When you try it out, images are indeed moved out of the clipboard tab and moved into the Images, but normal text get's moved there as well.

For me, the command moves only images. Maybe the clipboard contains both text and image format and that's why it gets moved.

Could this possibly be an issue? Or is this "overridden" from inside the command and not displayed in the GUI?

I think the input format: text label in this case only indicates that input() and placeholder %1 in the commands provide the clipboard text if available. It could be more specific: input format: text if available

Simple workaround would be to avoid the move if there is also text:

[Command]
Automatic=true
Command="
    copyq:
    var imageTab = '&Images'

    function hasFormat(formatRegExp, formats) {
        return !formats.every(function(e){
            return !e.match(formatRegExp)
        })
    }

    var formats = dataFormats()
    if (hasFormat(/^image\\//, formats) && !hasFormat(/^text\\/plain/, formats)) {
        setData(mimeOutputTab, imageTab)
    }"
Icon=\xf03e
Name=Move Images to Other Tab
moritzdietz commented 3 years ago

Ok so this should be ready now! 😃

hluk commented 3 years ago

Merged. Thanks!