From f4bf663180d76612b446fcaee6b4f41b6ac67676 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 7 May 2025 17:26:46 +0200 Subject: [PATCH] fix(image): Only focus image description on newly inserted image Fixes: #6843 Fixes: nextcloud/collectives#1740 Signed-off-by: Jonas --- src/components/Editor/MediaHandler.vue | 3 +++ src/nodes/ImageView.vue | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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() {