mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-22 22:27:30 +08:00
Past nodes fixed, codestyle
This commit is contained in:
@@ -1,18 +1,41 @@
|
||||
import GraphNode from "../graph/GraphNode"
|
||||
import KeyboardShortcut from "./KeyboardShortcut"
|
||||
import ObjectSerializer from "../serialization/ObjectSerializer"
|
||||
import Context from "./Context"
|
||||
|
||||
export default class Paste extends KeyboardShortcut {
|
||||
export default class Paste extends Context {
|
||||
|
||||
constructor(target, blueprint) {
|
||||
super(target, blueprint, {
|
||||
keys: ["Control", "C"]
|
||||
})
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
|
||||
this.serializer = new ObjectSerializer()
|
||||
|
||||
let self = this
|
||||
this.pasteHandle = e => self.pasted(e.clipboardData.getData("Text"))
|
||||
}
|
||||
|
||||
fire() {
|
||||
let value = navigator.clipboard.readText()
|
||||
let nodes = this.serializer.readMultiple(value).map(entity => new GraphNode(entity))
|
||||
blueprintFocused() {
|
||||
document.body.addEventListener("paste", this.pasteHandle)
|
||||
}
|
||||
|
||||
blueprintUnfocused() {
|
||||
document.body.removeEventListener("paste", this.pasteHandle)
|
||||
}
|
||||
|
||||
pasted(value) {
|
||||
let top = Number.MAX_SAFE_INTEGER
|
||||
let left = Number.MAX_SAFE_INTEGER
|
||||
let nodes = this.serializer.readMultiple(value).map(entity => {
|
||||
let node = new GraphNode(entity)
|
||||
top = Math.min(top, node.location[1])
|
||||
left = Math.min(left, node.location[0])
|
||||
return node
|
||||
})
|
||||
let mousePosition = this.blueprint.entity.mousePosition
|
||||
nodes.forEach(node => {
|
||||
node.location[0] += mousePosition[0] - left
|
||||
node.location[1] += mousePosition[1] - top
|
||||
})
|
||||
this.blueprint.addNode(...nodes)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user