decomp.me icon indicating copy to clipboard operation
decomp.me copied to clipboard

Scroll to line when clicking line number

Open 1superchip opened this issue 1 year ago • 2 comments

Scroll to line in source tab when line numbers in diff are clicked.

This does not highlight the newly selected line.

Related to https://github.com/decompme/decomp.me/issues/115. "Click a line number to jump to it in the source"

This should be reviewed.

1superchip avatar May 13 '24 16:05 1superchip

I forgot to write here, but I think we should adjust this to be more React friendly before merging. It's good to have this as a starting point, though. but stuff like getElementsByClassName isn't ideal for a react project like this

ethteck avatar May 22 '24 11:05 ethteck

Agreed with @ethteck. The way this PR is currently written requires that there only be one CodeMirror on the page at once, which is the case today, but might not be the case in future.

To do this in a more React-like way, a ref to the CodeMirror element should be provided via context, probably from the top-level Scratch editor component. Then when this button is clicked, you can do .getElementsByClassName on the ref instead of on the entire document.

bates64 avatar May 28 '24 01:05 bates64

I've been having a play with this. The current issue I'm running into is that the codemirror element only renders the lines it needs.. therefore if you have lines 1-30 on screen, you can scroll to 1-30.. but you cannot scroll to e.g. line 31 because that element does not exist.

image

mkst avatar Sep 21 '24 09:09 mkst

Gonna close this one as the change has been implemented - heavily based on your code, so thank you very much!

mkst avatar Sep 23 '24 06:09 mkst