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}`
// `\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.