Skip to content

Commit

Permalink
optimize scroll behavior in ConsolePanel (#1321)
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca authored Feb 12, 2025
1 parent 60b37bc commit 357c4cf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions spx-gui/src/components/editor/panels/ConsolePanel.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { throttle } from 'lodash'
import dayjs from 'dayjs'
import { computed } from 'vue'
import { useI18n } from '@/utils/i18n'
Expand All @@ -12,10 +13,18 @@ const i18n = useI18n()
const editorCtx = useEditorCtx()
const runtime = computed(() => editorCtx.runtime)
let isScrolledToBottom = true
const handleScroll = throttle((e: Event) => {
const el = e.target as HTMLElement
isScrolledToBottom = el.scrollHeight - el.scrollTop === el.clientHeight
}, 50)
function handleOutput(outputEl: unknown, i: number) {
if (i !== runtime.value.outputs.length - 1) return
if (!isScrolledToBottom) return
if (outputEl == null) return
;(outputEl as HTMLElement).scrollIntoView({ behavior: 'smooth' })
;(outputEl as HTMLElement).scrollIntoView({ behavior: 'instant' })
}
function humanizeTime(time: number) {
Expand Down Expand Up @@ -44,7 +53,7 @@ function getOutputSourceLocationText(output: RuntimeOutput) {
<UICardHeader>
{{ $t({ en: 'Console', zh: '控制台' }) }}
</UICardHeader>
<ul class="output-container">
<ul class="output-container" @scroll="handleScroll">
<UIEmpty v-if="runtime.outputs.length === 0" size="small">
<template v-if="runtime.running.mode === 'debug' && runtime.running.initializing">
{{ $t({ en: 'Initializing...', zh: '初始化中...' }) }}
Expand Down

0 comments on commit 357c4cf

Please sign in to comment.