mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-23 00:04:06 +00:00
[Refactor] Move copy handling to useCopy composable (#2451)
This commit is contained in:
@@ -43,6 +43,7 @@ import SideToolbar from '@/components/sidebar/SideToolbar.vue'
|
||||
import SecondRowWorkflowTabs from '@/components/topbar/SecondRowWorkflowTabs.vue'
|
||||
import { useCanvasDrop } from '@/composables/useCanvasDrop'
|
||||
import { useContextMenuTranslation } from '@/composables/useContextMenuTranslation'
|
||||
import { useCopy } from '@/composables/useCopy'
|
||||
import { useGlobalLitegraph } from '@/composables/useGlobalLitegraph'
|
||||
import { useWorkflowPersistence } from '@/composables/useWorkflowPersistence'
|
||||
import { CORE_SETTINGS } from '@/constants/coreSettings'
|
||||
@@ -263,6 +264,7 @@ useCanvasDrop(canvasRef)
|
||||
onMounted(async () => {
|
||||
useGlobalLitegraph()
|
||||
useContextMenuTranslation()
|
||||
useCopy()
|
||||
|
||||
comfyApp.vueAppReady = true
|
||||
|
||||
|
||||
39
src/composables/useCopy.ts
Normal file
39
src/composables/useCopy.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { useEventListener } from '@vueuse/core'
|
||||
|
||||
import { useCanvasStore } from '@/stores/graphStore'
|
||||
|
||||
/**
|
||||
* Adds a handler on copy that serializes selected nodes to JSON
|
||||
*/
|
||||
export const useCopy = () => {
|
||||
const canvasStore = useCanvasStore()
|
||||
|
||||
useEventListener(document, 'copy', (e) => {
|
||||
if (!(e.target instanceof Element)) {
|
||||
return
|
||||
}
|
||||
if (
|
||||
(e.target instanceof HTMLTextAreaElement &&
|
||||
e.target.type === 'textarea') ||
|
||||
(e.target instanceof HTMLInputElement && e.target.type === 'text')
|
||||
) {
|
||||
// Default system copy
|
||||
return
|
||||
}
|
||||
const isTargetInGraph =
|
||||
e.target.classList.contains('litegraph') ||
|
||||
e.target.classList.contains('graph-canvas-container') ||
|
||||
e.target.id === 'graph-canvas'
|
||||
|
||||
// copy nodes and clear clipboard
|
||||
const canvas = canvasStore.canvas
|
||||
if (isTargetInGraph && canvas?.selectedItems) {
|
||||
canvas.copyToClipboard()
|
||||
// clearData doesn't remove images from clipboard
|
||||
e.clipboardData?.setData('text', ' ')
|
||||
e.preventDefault()
|
||||
e.stopImmediatePropagation()
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -553,38 +553,6 @@ export class ComfyApp {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a handler on copy that serializes selected nodes to JSON
|
||||
*/
|
||||
#addCopyHandler() {
|
||||
document.addEventListener('copy', (e) => {
|
||||
if (!(e.target instanceof Element)) {
|
||||
return
|
||||
}
|
||||
if (
|
||||
(e.target instanceof HTMLTextAreaElement &&
|
||||
e.target.type === 'textarea') ||
|
||||
(e.target instanceof HTMLInputElement && e.target.type === 'text')
|
||||
) {
|
||||
// Default system copy
|
||||
return
|
||||
}
|
||||
const isTargetInGraph =
|
||||
e.target.classList.contains('litegraph') ||
|
||||
e.target.classList.contains('graph-canvas-container') ||
|
||||
e.target.id === 'graph-canvas'
|
||||
|
||||
// copy nodes and clear clipboard
|
||||
if (isTargetInGraph && this.canvas.selected_nodes) {
|
||||
this.canvas.copyToClipboard()
|
||||
e.clipboardData.setData('text', ' ') //clearData doesn't remove images from clipboard
|
||||
e.preventDefault()
|
||||
e.stopImmediatePropagation()
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse
|
||||
*
|
||||
@@ -1009,7 +977,6 @@ export class ComfyApp {
|
||||
this.#addDrawNodeHandler()
|
||||
this.#addDrawGroupsHandler()
|
||||
this.#addDropHandler()
|
||||
this.#addCopyHandler()
|
||||
this.#addPasteHandler()
|
||||
|
||||
await useExtensionService().invokeExtensionsAsync('setup')
|
||||
|
||||
Reference in New Issue
Block a user