Skip to content

Do not scroll on paste images#3400

Merged
juliaroldi merged 7 commits into
masterfrom
u/juliaroldi/image-paste
Jul 21, 2026
Merged

Do not scroll on paste images#3400
juliaroldi merged 7 commits into
masterfrom
u/juliaroldi/image-paste

Conversation

@juliaroldi

Copy link
Copy Markdown
Contributor

Pasting large images can cause the editor to jump far into view, which forces the user to scroll back to where the cursor was. When images are pasted, the caret should not be scrolled into view.

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-21 12:41 UTC

return {};
}

function isImageFragment(pasteFragment: DocumentFragment): boolean {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this check if the only pasted content is image?

Then you can name it isImageOnlyFragment

And to simplify the check, you can first querySelectorAll('img') and check there is exactly one result, and check element.textContent.trim() == ''

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, what if the pasted content is a table and its only content is an image? do you want to scroll in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should allow scrolling when a table contains only an image, and the same goes for an anchor element that contains only an image.

@juliaroldi
juliaroldi merged commit 43cfc1d into master Jul 21, 2026
8 checks passed
@juliaroldi
juliaroldi deleted the u/juliaroldi/image-paste branch July 21, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants