LCOV - code coverage report
Current view: top level - src/components/graph - TitleEditor.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 57 57
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2              :   <div
       3         2396 :     v-if="showInput"
       4              :     class="group-title-editor node-title-editor z-overlay p-1"
       5              :     :style="inputStyle"
       6              :   >
       7              :     <EditableText
       8              :       :is-editing="showInput"
       9              :       :model-value="editedTitle"
      10              :       class="size-full"
      11              :       :input-attrs="{
      12              :         'data-testid': 'node-title-input',
      13              :         class: 'size-full text-[length:inherit]'
      14              :       }"
      15              :       @edit="onEdit"
      16              :       @cancel="closeEditor"
      17              :     />
      18              :   </div>
      19              : </template>
      20              : 
      21              : <script setup lang="ts">
      22              : import { useEventListener } from '@vueuse/core'
      23              : import { computed, ref, watch } from 'vue'
      24              : import type { CSSProperties } from 'vue'
      25              : 
      26              : import EditableText from '@comfyorg/design-system/common/EditableText'
      27              : import { useAbsolutePosition } from '@/composables/element/useAbsolutePosition'
      28              : import {
      29              :   LGraphGroup,
      30              :   LGraphNode,
      31              :   LiteGraph
      32              : } from '@/lib/litegraph/src/litegraph'
      33              : import type { LiteGraphCanvasEvent } from '@/lib/litegraph/src/litegraph'
      34              : import { useSettingStore } from '@/platform/settings/settingStore'
      35              : import {
      36              :   useCanvasStore,
      37              :   useTitleEditorStore
      38              : } from '@/renderer/core/canvas/canvasStore'
      39              : import { app } from '@/scripts/app'
      40              : 
      41         2355 : const settingStore = useSettingStore()
      42              : 
      43         2355 : const showInput = ref(false)
      44         2355 : const editedTitle = ref('')
      45         2355 : const { style: inputPositionStyle, updatePosition } = useAbsolutePosition()
      46         2355 : const inputFontStyle = ref<CSSProperties>({})
      47         2355 : const inputStyle = computed<CSSProperties>(() => ({
      48              :   ...inputPositionStyle.value,
      49              :   ...inputFontStyle.value
      50              : }))
      51              : 
      52         2355 : const titleEditorStore = useTitleEditorStore()
      53         2355 : const canvasStore = useCanvasStore()
      54         2355 : const previousCanvasDraggable = ref(true)
      55              : 
      56         2355 : const onEdit = (newValue: string) => {
      57           14 :   if (titleEditorStore.titleEditorTarget && newValue?.trim()) {
      58           14 :     const trimmedTitle = newValue.trim()
      59           14 :     titleEditorStore.titleEditorTarget.title = trimmedTitle
      60              : 
      61              :     // If this is a subgraph node, sync the runtime subgraph name for breadcrumb reactivity
      62           14 :     const target = titleEditorStore.titleEditorTarget
      63           14 :     if (target instanceof LGraphNode && target.isSubgraphNode?.()) {
      64            1 :       target.subgraph.name = trimmedTitle
      65              :     }
      66              : 
      67           14 :     app.canvas.setDirty(true, true)
      68              :   }
      69           14 :   closeEditor()
      70              : }
      71              : 
      72           16 : function closeEditor() {
      73           16 :   showInput.value = false
      74           16 :   titleEditorStore.titleEditorTarget = null
      75           16 :   canvasStore.canvas!.allow_dragcanvas = previousCanvasDraggable.value
      76              : }
      77              : 
      78         2355 : watch(
      79              :   () => titleEditorStore.titleEditorTarget,
      80              :   (target) => {
      81           41 :     if (target === null) {
      82           16 :       return
      83              :     }
      84           25 :     editedTitle.value = target.title
      85           25 :     showInput.value = true
      86           25 :     const canvas = canvasStore.canvas!
      87           25 :     previousCanvasDraggable.value = canvas.allow_dragcanvas
      88           25 :     canvas.allow_dragcanvas = false
      89           25 :     const scale = canvas.ds.scale
      90              : 
      91           41 :     if (target instanceof LGraphGroup) {
      92           13 :       const group = target
      93           13 :       updatePosition({
      94              :         pos: group.pos,
      95              :         size: [group.size[0], group.titleHeight]
      96              :       })
      97           13 :       inputFontStyle.value = {
      98              :         fontSize: `${LiteGraph.GROUP_TEXT_SIZE * scale}px`
      99              :       }
     100           12 :     } else if (target instanceof LGraphNode) {
     101           12 :       const node = target
     102           12 :       const [x, y] = node.getBounding()
     103           12 :       updatePosition({
     104              :         pos: [x, y],
     105              :         size: [node.width, LiteGraph.NODE_TITLE_HEIGHT]
     106              :       })
     107           12 :       inputFontStyle.value = { fontSize: `${12 * scale}px` }
     108              :     }
     109              :   }
     110              : )
     111              : 
     112         2355 : const canvasEventHandler = (event: LiteGraphCanvasEvent) => {
     113          818 :   if (event.detail.subType === 'group-double-click') {
     114            3 :     if (!settingStore.get('Comfy.Group.DoubleClickTitleToEdit')) {
     115            1 :       return
     116              :     }
     117              : 
     118            2 :     const group: LGraphGroup = event.detail.group
     119            2 :     const [_, y] = group.pos
     120              : 
     121              :     const e = event.detail.originalEvent
     122              :     const relativeY = e.canvasY - y
     123              :     // Only allow editing if the click is on the title bar
     124            2 :     if (relativeY <= group.titleHeight) {
     125            2 :       titleEditorStore.titleEditorTarget = group
     126              :     }
     127          815 :   } else if (event.detail.subType === 'node-double-click') {
     128           52 :     if (!settingStore.get('Comfy.Node.DoubleClickTitleToEdit')) {
     129            1 :       return
     130              :     }
     131              : 
     132           51 :     const node: LGraphNode = event.detail.node
     133           51 :     const [_, y] = node.pos
     134              : 
     135              :     const e = event.detail.originalEvent
     136              :     const relativeY = e.canvasY - y
     137              :     // Only allow editing if the click is on the title bar
     138           51 :     if (relativeY <= 0) {
     139            9 :       titleEditorStore.titleEditorTarget = node
     140              :     }
     141              :   }
     142              : }
     143              : 
     144         2355 : useEventListener(document, 'litegraph:canvas', canvasEventHandler)
     145              : </script>
        

Generated by: LCOV version 2.0-1