fix: never duplicate targeted image replacement
This commit is contained in:
parent
bb73c27476
commit
732c90d022
1 changed files with 4 additions and 17 deletions
|
|
@ -1202,17 +1202,19 @@ export default function App() {
|
|||
const block = findImageBlockFromElement(event.target)
|
||||
if (!file || !block) return
|
||||
event.preventDefault()
|
||||
event.stopImmediatePropagation()
|
||||
pasteImageTargetRef.current = null
|
||||
void replaceEditorImageFile(file, block)
|
||||
}
|
||||
holder?.addEventListener("mousemove", handleEditorMouseMove)
|
||||
holder?.addEventListener("mouseleave", handleEditorMouseLeave)
|
||||
holder?.addEventListener("dragover", handleEditorDragOver)
|
||||
holder?.addEventListener("drop", handleEditorDrop)
|
||||
holder?.addEventListener("drop", handleEditorDrop, true)
|
||||
return () => {
|
||||
holder?.removeEventListener("mousemove", handleEditorMouseMove)
|
||||
holder?.removeEventListener("mouseleave", handleEditorMouseLeave)
|
||||
holder?.removeEventListener("dragover", handleEditorDragOver)
|
||||
holder?.removeEventListener("drop", handleEditorDrop)
|
||||
holder?.removeEventListener("drop", handleEditorDrop, true)
|
||||
clearEditorImageHover()
|
||||
clearImageCaptionNormalizationTimers()
|
||||
if (editorInstanceRef.current === editor) {
|
||||
|
|
@ -1222,20 +1224,6 @@ export default function App() {
|
|||
}
|
||||
}, [selectedArticle?.id, appSettings.signatureHtml])
|
||||
|
||||
async function insertImageFile(file: File) {
|
||||
if (!file.type.startsWith("image/")) return
|
||||
setEditorBusy(true)
|
||||
try {
|
||||
const url = await uploadImage(file)
|
||||
const caption = imageCaptionFromPostTitle()
|
||||
editorInstanceRef.current?.blocks.insert("image", { file: { url }, caption })
|
||||
scheduleEmptyImageCaptionNormalization()
|
||||
setEditorDirty(true)
|
||||
} finally {
|
||||
setEditorBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
function findImageBlockFromElement(target: EventTarget | null) {
|
||||
const editor = editorInstanceRef.current
|
||||
if (!editor || !(target instanceof Element)) return null
|
||||
|
|
@ -1306,7 +1294,6 @@ export default function App() {
|
|||
const editor = editorInstanceRef.current
|
||||
const block = blockToReplace ?? editorImageHoverBlockRef.current
|
||||
if (!editor || !block || block.name !== "image") {
|
||||
await insertImageFile(file)
|
||||
return
|
||||
}
|
||||
setEditorBusy(true)
|
||||
|
|
|
|||
Loading…
Reference in a new issue