HakonHarnes / img-clip.nvim

Effortlessly embed images into any markup language, like LaTeX, Markdown or Typst
MIT License
443 stars 7 forks source link

Copy_Images in drag and drop and "normal" copying not working. #40

Closed LuposX closed 6 months ago

LuposX commented 6 months ago

Describe the bug I have two separate problems, but I will list them in on issue because I suspect that they might be linked. The first one is when I copy a Image I can't insert it into my markdown file via the command PasteImage I get the error: Clipboard content is not a Image. The second one is changing the values of copy_image doesn't change the behavior of the plugin.

Steps to reproduce For the first one:

  1. Open "Thunar", "Dolphin" or "Nautilus"
  2. Copy the image by either pressing "STRG + C" or by first pressing right click and then copy
  3. Use the command PasteImage in a markdown file
  4. See error: Clipboard content is not a Image.

For the second one:

  1. Change the value of copy_image to true
  2. Trying to copy something in normal mode
  3. this will lead to the file not being copied in the correct attachment folder, instead it will only link to the existing image.

Screenshots https://github.com/HakonHarnes/img-clip.nvim/assets/36456825/c22b37b6-a2ce-4acf-a6d4-54d436830379

https://github.com/HakonHarnes/img-clip.nvim/assets/36456825/07edd180-068c-4f55-a1ad-497e4d064d76

Desktop (please complete the following information):

My Config

{
    "HakonHarnes/img-clip.nvim",
    event = "BufEnter",
    opts = {
      -- add options here
      -- or leave it empty to use the default settings
      default = {
        debug = true,
        dir_path = "attachments",
        relative_to_current_file = true,
        prompt_fo_file_name = false,
        insert_mode_after_paste = true,

        drag_and_drop = {
          enables = true,
          copy_image = true,
          insert_mode = true,
       },
      },
    },
    keys = {
      -- suggested keymap
      { "<leader>p", "<cmd>PasteImage<cr>", desc = "Paste clipboard image" },
    },
  },
HakonHarnes commented 6 months ago

Thanks for reporting the issue!

First issue: Copying from file browser does not work

This doesn't work because the clipboard content is indeed not an image. It's actually a reference to a file (rather than the content of the file). I can account for this in code though, by allowing file paths as input to the PasteImage function and then just copying the file to the correct location (this is how drag and drop works currently). I'll look into it sometime this week.

Second issue: copy_image is not working

This is due to a typo in your configuration. It's copy_images, not copy_image:

drag_and_drop = {
          copy_images = true,
          insert_mode = true,
       },
LuposX commented 6 months ago

@HakonHarnes Thank you for your help, great work!

HakonHarnes commented 6 months ago

@LuposX How is feat/allow-file-paths-as-input working out for you? Just set the branch option in Lazy accordingly and update to try it out.