diff --git a/src/components/Editor/MediaHandler.vue b/src/components/Editor/MediaHandler.vue index 3f491d15115..4c0eb95d442 100644 --- a/src/components/Editor/MediaHandler.vue +++ b/src/components/Editor/MediaHandler.vue @@ -226,6 +226,9 @@ export default { // Scroll image into view this.$editor.commands.scrollIntoView() + // Store last inserted attachment src to focus it in ImageView.vue + this.$editor.commands.setMeta('insertedAttachmentSrc', { src }) + emit('text:image-node:add', null) }, }, diff --git a/src/nodes/ImageView.vue b/src/nodes/ImageView.vue index b0d2fb60572..31332836352 100644 --- a/src/nodes/ImageView.vue +++ b/src/nodes/ImageView.vue @@ -170,6 +170,7 @@ export default { showImageModal: false, imageIndex: null, isEditable: false, + isLastInserted: false, embeddedImageList: [], } }, @@ -223,6 +224,12 @@ export default { this.editor.on('update', ({ editor }) => { this.isEditable = editor.isEditable }) + this.editor.on('transaction', ({ transaction }) => { + const trMeta = transaction.getMeta('insertedAttachmentSrc') + if (trMeta?.src === this.src) { + this.isLastInserted = true + } + }) this.loadPreview().catch(this.onImageLoadFailure) }, methods: { @@ -265,7 +272,9 @@ export default { onLoaded() { this.loaded = true this.$nextTick(() => { - this.$refs.altInput?.focus() + if (this.isLastInserted) { + this.$refs.altInput?.focus() + } }) }, async updateEmbeddedImageList() {