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

Open
opened 2026-10-05 02:47:08 +02:00 by adam · 8 comments
Owner

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?
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? <!-- github-sync-id:1634703675 -->
Author
Owner

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?

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? <!-- github-comment-id:1713606445 -->
Author
Owner

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

It was not "planned" yet, but you can send in a PR if you want. <!-- github-comment-id:1713658894 -->
Author
Owner

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?

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? <!-- github-comment-id:1713727265 -->
Author
Owner

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

Makes sense to me. We can always change or enhance it when we can test it out. <!-- github-comment-id:1713771127 -->
Author
Owner

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

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 <!-- github-comment-id:1719458871 -->
Author
Owner

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.

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 <!-- github-comment-id:1719699818 -->
Author
Owner

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"
}
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): ```json { "markdown.copyFiles.destination": { "**/*": "${documentWorkspaceFolder}/images/${documentBaseName}/" }, "markdown.occurrencesHighlight.enabled": true, "markdown.updateLinksOnFileMove.enabled": "prompt" } ``` <!-- github-comment-id:1727593562 -->
Author
Owner

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.

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. <!-- github-comment-id:1727597302 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/vscode-front-matter#433