badlydrawnrob / anki

Learn to code with Anki — flashcards and themes for all learning levels. Master your programming language of choice!
MIT License
719 stars 61 forks source link

Scroll to first `{{c1::cloze tag}}` on Missing! card reveal #133

Closed badlydrawnrob closed 2 months ago

badlydrawnrob commented 7 months ago

It would be nice to have the reverse card move down to the answer so that a long piece of code doesn't have to be scrolled manually. See this issue for more details.

This is a "nice to have" and not an essential feature. I'll leave it up to the user to use (or not)

If anyone has a solution that works, let me know. This code was suggested but doesn't work for me:[^1]

<script>
onUpdateHook.push(() => {
  document.querySelector(".cloze[data-ordinal='1']").scrollIntoView();
});
</script>

It would mean a long card like this one could would scroll into view with the first cloze deletion answer at the top of the screen:

Screenshot 2024-02-07 at 14 02 59

[^1]: In general it's probably best practice to not use javascript in cards, but another option could be selecting :nth-of-type(1) or some other trickery like scrollIntoView() but so far nothing I've tried works.

badlydrawnrob commented 2 months ago

This doesn't seem to be possible without a considerable amount of effort. I can always use a way to highlight the line (or blur out surrounding text on reveal) — however that requires adding a class to the surrounding <span> line which isn't that good a user experience.