vscode-front-matter icon indicating copy to clipboard operation
vscode-front-matter copied to clipboard

Enhancement: Allow to store images from your clipboard in the assets folder

Open estruyf opened this issue 1 year ago • 8 comments

Allow to store images from your clipboard to your assets/public folder.

Thoughts/questions

  • When pasting, should we ask in which folder to add the image?
  • Should there be a default image location where these clipboard images are saved?

estruyf avatar Mar 21 '23 21:03 estruyf

We would love to see pasted images being stored in a default image location.

Do you have any plans to implement that in the near future ? Would you accept a PR?

IntranetFactory avatar Sep 11 '23 10:09 IntranetFactory

It was not "planned" yet, but you can send in a PR if you want.

estruyf avatar Sep 11 '23 11:09 estruyf

We will try if we can

a. add a new setting imagesFolder b. when the setting is present pasted images are saved in that folder c. use a GUID as image name

would that make sense?

IntranetFactory avatar Sep 11 '23 11:09 IntranetFactory

Makes sense to me. We can always change or enhance it when we can test it out.

estruyf avatar Sep 11 '23 12:09 estruyf

Would someone be able to help point me in the direction of where the logic that reacts to an image paste and does the rename+save exists? I've never looked at a VS extension source before and I'm going dizzy trying to locate it, github searches for 'image', 'clipboard' and 'paste' didn't get me to an obvious answer, and I've tried debugging with breakpoints in all the services that came up for the 'image' search. Even wrapping the exported copyFile and writeFile promises and adding breakpoints did not get hit. Breakpoints generally are getting hit though so I don't think it's a problem with debugger setup

olliejm avatar Sep 14 '23 13:09 olliejm

There is no way to access the clipboard listeners like onPaste or onCopy. The only way would be to override the OOTB paste command.

Steps to do this:

  • Create a new command: frontMatter.onPaste
  • In the command, check if there is an image, and do what you need to do; if it is not an image, you can call the default editor.action.clipboardPasteAction command from VSCode
  • Add a keybindings for the new command, which overrides the default one (editor.action.clipboardPasteAction)

I found an extension that already does this - https://github.com/aefernandes/vscode-clipboard-history-extension.

  • Implementing the command: https://github.com/aefernandes/vscode-clipboard-history-extension/blob/master/src/clipboard.ts#L84-L86
  • Overriding of the keybindings: https://github.com/aefernandes/vscode-clipboard-history-extension/blob/master/package.json#L84-L89

estruyf avatar Sep 14 '23 15:09 estruyf

We found that the following .vscode settings already cover most of our needs (have pasted images in one folder, reduce naming conflicts, make it easy to move documents without breaking images):

{
    "markdown.copyFiles.destination": {
        "**/*": "${documentWorkspaceFolder}/images/${documentBaseName}/"
    },
    "markdown.occurrencesHighlight.enabled": true,
    "markdown.updateLinksOnFileMove.enabled": "prompt"
}

IntranetFactory avatar Sep 20 '23 12:09 IntranetFactory

Thanks @IntranetFactory for your insights on this! If it is already in VSCode, we could indeed use it. The only downside is when you would like to use media snippets from FM.

estruyf avatar Sep 20 '23 12:09 estruyf