sites icon indicating copy to clipboard operation
sites copied to clipboard

Adding a new component in homepage REPL widgets causes scroll jump

Open Rich-Harris opened this issue 5 years ago • 7 comments

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

Rich-Harris avatar Jun 06 '19 17:06 Rich-Harris

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.

Riyeshp avatar Jun 06 '19 21:06 Riyeshp

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?

mrkishi avatar Jun 07 '19 01:06 mrkishi

@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 avatar Jun 07 '19 12:06 Rich-Harris

@Rich-Harris Ah! Makes sense! Were there any blockers from using cm.swapDoc and CodeMirror's documents? If not, I can PR that in.

mrkishi avatar Jun 07 '19 13:06 mrkishi

The blocker was me not knowing it existed

Rich-Harris avatar Jun 07 '19 13:06 Rich-Harris

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 ?

Conduitry avatar Jun 07 '19 13:06 Conduitry

Is this still something we're looking at? And if so, is the PR at sveltejs/svelte-repl#10 still valid for fixing it?

willamesoares avatar Jul 28 '20 04:07 willamesoares