Insert image at cursor position (#874)
This commit is contained in:
parent
a067a9fcf1
commit
8cd147f67f
@ -288,10 +288,17 @@ export function MarkdownInput ({ label, topLevel, groupClassName, onChange, onKe
|
|||||||
ref={imageUploadRef}
|
ref={imageUploadRef}
|
||||||
className='d-flex align-items-center me-1'
|
className='d-flex align-items-center me-1'
|
||||||
onUpload={file => {
|
onUpload={file => {
|
||||||
let text = innerRef.current.value
|
const uploadMarker = `![Uploading ${file.name}…]()`
|
||||||
if (text) text += '\n\n'
|
const text = innerRef.current.value
|
||||||
text += `![Uploading ${file.name}…]()`
|
const cursorPosition = innerRef.current.selectionStart || text.length
|
||||||
helpers.setValue(text)
|
let preMarker = text.slice(0, cursorPosition)
|
||||||
|
const postMarker = text.slice(cursorPosition)
|
||||||
|
// when uploading multiple files at once, we want to make sure the upload markers are separated by blank lines
|
||||||
|
if (preMarker && !/\n+\s*$/.test(preMarker)) {
|
||||||
|
preMarker += '\n\n'
|
||||||
|
}
|
||||||
|
const newText = preMarker + uploadMarker + postMarker
|
||||||
|
helpers.setValue(newText)
|
||||||
setSubmitDisabled?.(true)
|
setSubmitDisabled?.(true)
|
||||||
}}
|
}}
|
||||||
onSuccess={({ url, name }) => {
|
onSuccess={({ url, name }) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user