MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / processKey

Method processKey

src/LGraphCanvas.ts:3255–3336  ·  view source on GitHub ↗

* process a key event

(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

3253 * process a key event
3254 */
3255 processKey(e: KeyboardEvent): void {
3256 this.#shiftDown = e.shiftKey
3257
3258 const { graph } = this
3259 if (!graph) return
3260
3261 let block_default = false
3262 // @ts-expect-error
3263 if (e.target.localName == "input") return
3264
3265 if (e.type == "keydown") {
3266 // TODO: Switch
3267 if (e.key === " ") {
3268 // space
3269 this.read_only = true
3270 if (this._previously_dragging_canvas === null) {
3271 this._previously_dragging_canvas = this.dragging_canvas
3272 }
3273 this.dragging_canvas = this.pointer.isDown
3274 block_default = true
3275 } else if (e.key === "Escape") {
3276 // esc
3277 if (this.linkConnector.isConnecting) {
3278 this.linkConnector.reset()
3279 e.preventDefault()
3280 return
3281 }
3282 this.node_panel?.close()
3283 this.options_panel?.close()
3284 if (this.node_panel || this.options_panel) block_default = true
3285 } else if (e.keyCode === 65 && e.ctrlKey) {
3286 // select all Control A
3287 this.selectItems()
3288 block_default = true
3289 } else if (e.keyCode === 67 && (e.metaKey || e.ctrlKey) && !e.shiftKey) {
3290 // copy
3291 if (this.selected_nodes) {
3292 this.copyToClipboard()
3293 block_default = true
3294 }
3295 } else if (e.keyCode === 86 && (e.metaKey || e.ctrlKey)) {
3296 // paste
3297 this.pasteFromClipboard({ connectInputs: e.shiftKey })
3298 } else if (e.key === "Delete" || e.key === "Backspace") {
3299 // delete or backspace
3300 // @ts-expect-error
3301 if (e.target.localName != "input" && e.target.localName != "textarea") {
3302 if (this.selectedItems.size === 0) {
3303 this.#noItemsSelected()
3304 return
3305 }
3306
3307 this.deleteSelected()
3308 block_default = true
3309 }
3310 }
3311
3312 // TODO

Callers

nothing calls this directly

Calls 8

selectItemsMethod · 0.95
copyToClipboardMethod · 0.95
pasteFromClipboardMethod · 0.95
#noItemsSelectedMethod · 0.95
deleteSelectedMethod · 0.95
changeMethod · 0.80
closeMethod · 0.65
resetMethod · 0.45

Tested by

no test coverage detected