mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-26 17:30:07 +00:00
Scroll to active offscreen tab when opened (#3320)
Co-authored-by: Benjamin Lu <templu1107@proton.me>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="workflow-tabs-container flex flex-row max-w-full h-full">
|
<div class="workflow-tabs-container flex flex-row max-w-full h-full">
|
||||||
<ScrollPanel
|
<ScrollPanel
|
||||||
|
ref="scrollPanelRef"
|
||||||
class="overflow-hidden no-drag"
|
class="overflow-hidden no-drag"
|
||||||
:pt:content="{
|
:pt:content="{
|
||||||
class: 'p-0 w-full',
|
class: 'p-0 w-full',
|
||||||
@@ -44,7 +45,7 @@ import Button from 'primevue/button'
|
|||||||
import ContextMenu from 'primevue/contextmenu'
|
import ContextMenu from 'primevue/contextmenu'
|
||||||
import ScrollPanel from 'primevue/scrollpanel'
|
import ScrollPanel from 'primevue/scrollpanel'
|
||||||
import SelectButton from 'primevue/selectbutton'
|
import SelectButton from 'primevue/selectbutton'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, nextTick, ref, watch } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import WorkflowTab from '@/components/topbar/WorkflowTab.vue'
|
import WorkflowTab from '@/components/topbar/WorkflowTab.vue'
|
||||||
@@ -70,6 +71,7 @@ const workflowService = useWorkflowService()
|
|||||||
const workflowBookmarkStore = useWorkflowBookmarkStore()
|
const workflowBookmarkStore = useWorkflowBookmarkStore()
|
||||||
const rightClickedTab = ref<WorkflowOption | undefined>()
|
const rightClickedTab = ref<WorkflowOption | undefined>()
|
||||||
const menu = ref()
|
const menu = ref()
|
||||||
|
const scrollPanelRef = ref()
|
||||||
|
|
||||||
const workflowToOption = (workflow: ComfyWorkflow): WorkflowOption => ({
|
const workflowToOption = (workflow: ComfyWorkflow): WorkflowOption => ({
|
||||||
value: workflow.path,
|
value: workflow.path,
|
||||||
@@ -175,6 +177,37 @@ const handleWheel = (event: WheelEvent) => {
|
|||||||
left: scrollElement.scrollLeft + scrollAmount
|
left: scrollElement.scrollLeft + scrollAmount
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scroll to active offscreen tab when opened
|
||||||
|
watch(
|
||||||
|
() => workflowStore.activeWorkflow,
|
||||||
|
() => {
|
||||||
|
if (!selectedWorkflow.value) return
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
const activeTabElement = document.querySelector('.p-togglebutton-checked')
|
||||||
|
if (!activeTabElement || !scrollPanelRef.value) return
|
||||||
|
|
||||||
|
const container = scrollPanelRef.value.$el.querySelector(
|
||||||
|
'.p-scrollpanel-content'
|
||||||
|
)
|
||||||
|
if (!container) return
|
||||||
|
|
||||||
|
const tabRect = activeTabElement.getBoundingClientRect()
|
||||||
|
const containerRect = container.getBoundingClientRect()
|
||||||
|
|
||||||
|
const offsetLeft = tabRect.left - containerRect.left
|
||||||
|
const offsetRight = tabRect.right - containerRect.right
|
||||||
|
|
||||||
|
if (offsetRight > 0) {
|
||||||
|
container.scrollBy({ left: offsetRight })
|
||||||
|
} else if (offsetLeft < 0) {
|
||||||
|
container.scrollBy({ left: offsetLeft })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user