Skip to content

[stable30] fix(image): Only focus image description on newly inserted image #7207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/Editor/MediaHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
Expand Down
11 changes: 10 additions & 1 deletion src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export default {
showImageModal: false,
imageIndex: null,
isEditable: false,
isLastInserted: false,
embeddedImageList: [],
}
},
Expand Down Expand Up @@ -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)
},
Expand Down Expand Up @@ -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() {
Expand Down
Loading