|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import type { DevToolsLogEntry, DevToolsLogEntryFrom, DevToolsLogLevel } from '@vitejs/devtools-kit' |
3 | 3 | import type { DocksContext } from '@vitejs/devtools-kit/client' |
4 | | -import { useClipboard, useTimeAgo } from '@vueuse/core' |
5 | | -import { computed, onMounted, ref, watch } from 'vue' |
| 4 | +import { useClipboard, useTimeAgo, whenever } from '@vueuse/core' |
| 5 | +import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from 'vue' |
6 | 6 | import { markLogsAsRead, useLogs } from '../../state/logs' |
7 | 7 | import FilterToggles from '../display/FilterToggles.vue' |
8 | 8 | import HashBadge from '../display/HashBadge.vue' |
@@ -168,6 +168,20 @@ watch(selectedEntry, async (entry) => { |
168 | 168 | await props.context.rpc.call('devtoolskit:internal:logs:update', entry.id, { autoDelete: 0 }) |
169 | 169 | }) |
170 | 170 |
|
| 171 | +const logListEl = useTemplateRef('logListEl') |
| 172 | +
|
| 173 | +whenever(() => logsState.pendingSelectId, async (id) => { |
| 174 | + if (!id) |
| 175 | + return |
| 176 | +
|
| 177 | + logsState.pendingSelectId = null |
| 178 | + selectedId.value = id |
| 179 | +
|
| 180 | + await nextTick() |
| 181 | + logListEl.value?.querySelector<HTMLElement>('[data-selected]') |
| 182 | + ?.scrollIntoView({ block: 'center', behavior: 'smooth' }) |
| 183 | +}, { immediate: true }) |
| 184 | +
|
171 | 185 | const selectedTimeAgo = useTimeAgo(computed(() => selectedEntry.value?.timestamp ?? Date.now())) |
172 | 186 | const { copy: copyStacktrace, copied: stacktraceCopied } = useClipboard() |
173 | 187 |
|
@@ -306,13 +320,14 @@ onMounted(() => { |
306 | 320 | <!-- Content --> |
307 | 321 | <div class="h-full of-hidden" :class="selectedEntry ? 'grid grid-cols-[1fr_1fr]' : ''"> |
308 | 322 | <!-- Log list --> |
309 | | - <div class="h-full of-y-auto"> |
| 323 | + <div ref="logListEl" class="h-full of-y-auto"> |
310 | 324 | <div v-if="filteredEntries.length === 0" class="flex items-center justify-center h-full op50 text-sm"> |
311 | 325 | No logs |
312 | 326 | </div> |
313 | 327 | <div |
314 | 328 | v-for="entry of filteredEntries" |
315 | 329 | :key="entry.id" |
| 330 | + :data-selected="selectedId === entry.id || undefined" |
316 | 331 | class="w-full text-left border-b border-base hover:bg-active transition border-l-2 text-sm group cursor-pointer" |
317 | 332 | :class="[ |
318 | 333 | selectedId === entry.id ? 'bg-active' : '', |
|
0 commit comments