Skip to content

Commit 495389b

Browse files
mejo-backportbot[bot]
authored andcommitted
fix(image): Only focus image description on newly inserted image
Fixes: #6843 Fixes: nextcloud/collectives#1740 Signed-off-by: Jonas <jonas@freesources.org>
1 parent ea90e69 commit 495389b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/components/Editor/MediaHandler.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ export default {
194194
// Scroll image into view
195195
this.$editor.commands.scrollIntoView()
196196
197+
// Store last inserted attachment src to focus it in ImageView.vue
198+
this.$editor.commands.setMeta('insertedAttachmentSrc', { src })
199+
197200
emit('text:image-node:add', null)
198201
},
199202
},

src/nodes/ImageView.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export default {
164164
showImageModal: false,
165165
imageIndex: null,
166166
isEditable: false,
167+
isLastInserted: false,
167168
embeddedImageList: [],
168169
}
169170
},
@@ -220,6 +221,12 @@ export default {
220221
this.editor.on('update', ({ editor }) => {
221222
this.isEditable = editor.isEditable
222223
})
224+
this.editor.on('transaction', ({ transaction }) => {
225+
const trMeta = transaction.getMeta('insertedAttachmentSrc')
226+
if (trMeta?.src === this.src) {
227+
this.isLastInserted = true
228+
}
229+
})
223230
this.loadPreview()
224231
.catch(this.onImageLoadFailure)
225232
},
@@ -263,7 +270,9 @@ export default {
263270
onLoaded() {
264271
this.loaded = true
265272
this.$nextTick(() => {
266-
this.$refs.altInput?.focus()
273+
if (this.isLastInserted) {
274+
this.$refs.altInput?.focus()
275+
}
267276
})
268277
},
269278
async updateEmbeddedImageList() {

0 commit comments

Comments
 (0)