0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Redmineに画像ペースト機能を追加

Last updated at Posted at 2025-04-07
window.issue_notes.addEventListener('paste', e => {
    const textarea = window.issue_notes
    const input = document.querySelector('input[type=file]')
    const dataTransfer = new DataTransfer()
    for (const i in [...e.clipboardData.files]) {
        let file = e.clipboardData.files[i]
        if (file.type.includes('image')) {
            let prefix = new Date().toLocaleString('sv').replaceAll(/\D/g, '')
            if (e.clipboardData.files.length > 1) prefix += `-${i}`
            const fileName = `${prefix}-${file.name}`
            // `![](${fileName})\n`
            textarea.setRangeText(`!${fileName}!\n`, textarea.selectionStart, textarea.selectionEnd, 'end')
            file = new File([file], fileName, file)
        }
        dataTransfer.items.add(file)
    }
    input.files = dataTransfer.files
    input.dispatchEvent(new Event('change'))
})

Allow pasting screenshots from clipboard (#3816 contributed by Takenori TAKAKI)

You can now paste image data from your clipboard when editing formatted text, eg. using CTRL+V. That will automatically upload the image as an attachment and append the appriorate tag in the text in order to display the image inline. No more need to save your screenshot as a file before uploading it to Redmine.
Note that you can also drag and drop an image file into the textarea to get the same result.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?