diff --git a/src/components/Editor/MediaHandler.vue b/src/components/Editor/MediaHandler.vue index 0e28b1de398..9b42cb66194 100644 --- a/src/components/Editor/MediaHandler.vue +++ b/src/components/Editor/MediaHandler.vue @@ -194,6 +194,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 deeef1864ed..7198d85aa23 100644 --- a/src/nodes/ImageView.vue +++ b/src/nodes/ImageView.vue @@ -164,6 +164,7 @@ export default { showImageModal: false, imageIndex: null, isEditable: false, + isLastInserted: false, embeddedImageList: [], } }, @@ -220,6 +221,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) }, @@ -263,7 +270,9 @@ export default { onLoaded() { this.loaded = true this.$nextTick(() => { - this.$refs.altInput?.focus() + if (this.isLastInserted) { + this.$refs.altInput?.focus() + } }) }, async updateEmbeddedImageList() {