From a8ac0bba3a53f207d202ccfc10ae6b7c11620374 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Tue, 9 Jul 2024 15:01:59 +0200 Subject: [PATCH] scroll to line numbers and nearest --- report-viewer/src/components/fileDisplaying/CodeLine.vue | 8 -------- report-viewer/src/components/fileDisplaying/CodePanel.vue | 6 +++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/report-viewer/src/components/fileDisplaying/CodeLine.vue b/report-viewer/src/components/fileDisplaying/CodeLine.vue index bcced0c92b..e0644f65d4 100644 --- a/report-viewer/src/components/fileDisplaying/CodeLine.vue +++ b/report-viewer/src/components/fileDisplaying/CodeLine.vue @@ -57,14 +57,6 @@ function matchSelected(match?: MatchInSingleFile) { const lineRef = ref(null) -function scrollTo() { - if (lineRef.value) { - lineRef.value.scrollIntoView({ block: 'center' }) - } -} - -defineExpose({ scrollTo }) - interface TextPart { line: string match?: MatchInSingleFile diff --git a/report-viewer/src/components/fileDisplaying/CodePanel.vue b/report-viewer/src/components/fileDisplaying/CodePanel.vue index 75010c1eac..4018523d36 100644 --- a/report-viewer/src/components/fileDisplaying/CodePanel.vue +++ b/report-viewer/src/components/fileDisplaying/CodePanel.vue @@ -30,6 +30,7 @@ v-for="(_, index) in codeLines" :key="index" class="col-span-1 col-start-1 row-span-1 text-right" + ref="lineRefs" :style="{ gridRowStart: index + 1 }" @@ -40,7 +41,6 @@ ([]) +const lineRefs = ref([]) const codeLines: Ref<{ line: string; matches: MatchInSingleFile[] }[]> = computed(() => highlight(props.file.data, props.highlightLanguage).map((line, index) => { @@ -116,7 +116,7 @@ function matchSelected(match: Match) { function scrollTo(lineNumber: number) { collapsed.value = false nextTick(function () { - lineRefs.value[lineNumber - 1].scrollTo() + lineRefs.value[lineNumber - 1].scrollIntoView({ block: 'nearest' }) }) }