From 7022293e310c92743f67a4f69ce7d8c991ca38ec Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:17:00 -0300 Subject: [PATCH] fix: improve autoscroll to highlighted block --- .../META-INF/resources/frontend/code-viewer.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/resources/META-INF/resources/frontend/code-viewer.ts b/src/main/resources/META-INF/resources/frontend/code-viewer.ts index e56a576..1c8d5e6 100644 --- a/src/main/resources/META-INF/resources/frontend/code-viewer.ts +++ b/src/main/resources/META-INF/resources/frontend/code-viewer.ts @@ -449,12 +449,16 @@ pre[class*="language-"] { div.style.top= `calc( ${top}px + 0.75em)`; div.style.height= `${height}px`; - //scroll to the begin of the marked block - if ((begin as any).scrollIntoViewIfNeeded) { - (begin as any).scrollIntoViewIfNeeded(); - } else { - (begin as any).scrollIntoView() + const scrollIntoView = elem => { + if ((elem as any).scrollIntoViewIfNeeded) { + (elem as any).scrollIntoViewIfNeeded(); + } else { + (elem as any).scrollIntoView() + } } + + scrollIntoView(end); + scrollIntoView(begin); } } }