sites
sites copied to clipboard
Adding a new component in homepage REPL widgets causes scroll jump
Technically this issue probably belongs in the svelte-repl repo, but I'll forget about it if it's there
https://mobile.twitter.com/MohsenKhakbiz/status/1136676705110827008
Hi Rich.. I hope this piece of information will be of any help to you to track down this bug.
//ComponentSelector.svelte
const component = {
name: uid++ ? `Component${uid}` : 'Component1',
type: 'svelte',
source: ''
};
editing = component;
setTimeout(() => {
// TODO we can do this without IDs
document.getElementById(component.name).scrollIntoView(false);
});
"document.getElementById(component.name).scrollIntoView(false);" this line seems to be creating that jump in the web page.
Related issue at sveltejs/svelte-repl#9 and PR at sveltejs/svelte-repl#10. I'm not sure what the right approach should be — what's the original intention for the scroll?
@Riyeshp thanks
@mrkishi Without it, if you switch to (or create) a new component, CodeMirror updates the editor content, but retains the old scroll position, which is a bit unsettling
@Rich-Harris Ah! Makes sense! Were there any blockers from using cm.swapDoc
and CodeMirror's documents? If not, I can PR that in.
The blocker was me not knowing it existed
I didn't know about swapDoc either. Does that seem like it could also be used to take care of https://github.com/sveltejs/svelte-repl/issues/3 ?
Is this still something we're looking at? And if so, is the PR at sveltejs/svelte-repl#10 still valid for fixing it?