mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-18 12:24:51 +08:00
Select all nodes functionality added
This commit is contained in:
@@ -8,7 +8,10 @@ export default class Copy extends Context {
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
this.copyHandler = _ => self.copied()
|
||||
this.copyHandler = _ => {
|
||||
self.copied()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
blueprintFocused() {
|
||||
|
||||
@@ -47,5 +47,6 @@ export default class Paste extends Context {
|
||||
node.setSelected(true)
|
||||
node.snapToGrid()
|
||||
})
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
21
js/input/keybaord/KeyboardSelectAll.js
Executable file
21
js/input/keybaord/KeyboardSelectAll.js
Executable file
@@ -0,0 +1,21 @@
|
||||
import KeyboardShortcut from "./KeyboardShortcut"
|
||||
import Configuration from "../../Configuration"
|
||||
|
||||
|
||||
export default class KeyboardSelectAll extends KeyboardShortcut {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLElement} target
|
||||
* @param {import("../../Blueprint").default} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = KeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey)
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
fire() {
|
||||
this.blueprint.selectAll()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,38 @@
|
||||
import Configuration from "../../Configuration"
|
||||
import Context from "../Context"
|
||||
import Parsimmon from "parsimmon"
|
||||
|
||||
let P = Parsimmon
|
||||
|
||||
class KeyGrammar {
|
||||
|
||||
// Creates a grammar where each alternative is the string from ModifierKey mapped to a number for bit or use
|
||||
ModifierKey = r => P.alt(...Configuration.ModifierKeys.map((v, i) => P.string(v).map(_ => 1 << i)))
|
||||
Key = r => P.alt(...Object.keys(Configuration.Keys).map(v => P.string(v))).map(v => Configuration.Keys[v])
|
||||
KeyboardShortcut = r => P.alt(
|
||||
P.seqMap(
|
||||
P.seqMap(r.ModifierKey, P.optWhitespace, P.string(Configuration.keysSeparator), (v, _, __) => v)
|
||||
.atLeast(1)
|
||||
.map(v => v.reduce((acc, cur) => acc | cur)),
|
||||
P.optWhitespace,
|
||||
r.Key,
|
||||
(modifierKeysFlag, _, key) => ({
|
||||
key: key,
|
||||
ctrlKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Ctrl"))),
|
||||
shiftKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Shift"))),
|
||||
altKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Alt"))),
|
||||
metaKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Meta")))
|
||||
})
|
||||
),
|
||||
r.Key.map(v => ({ key: v }))
|
||||
)
|
||||
.trim(P.optWhitespace)
|
||||
}
|
||||
|
||||
export default class KeyboardShortcut extends Context {
|
||||
|
||||
static keyGrammar = P.createLanguage(new KeyGrammar())
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
@@ -23,7 +54,10 @@ export default class KeyboardShortcut extends Context {
|
||||
&& e.metaKey === self.metaKey
|
||||
) {
|
||||
self.fire()
|
||||
e.preventDefault()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +67,10 @@ export default class KeyboardShortcut extends Context {
|
||||
* @returns {Object}
|
||||
*/
|
||||
static keyOptionsParse(options, keyString) {
|
||||
options.key = keyString
|
||||
options = {
|
||||
...options,
|
||||
...KeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ export default class MouseClickDrag extends Pointing {
|
||||
document.addEventListener("mouseup", self.mouseUpHandler)
|
||||
self.clickedPosition = self.getLocation(e)
|
||||
self.clicked(self.clickedPosition)
|
||||
return true
|
||||
}
|
||||
break
|
||||
default:
|
||||
@@ -39,6 +40,7 @@ export default class MouseClickDrag extends Pointing {
|
||||
}
|
||||
break
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
this.mouseStartedMovingHandler = e => {
|
||||
|
||||
@@ -9,6 +9,7 @@ export default class MouseTracking extends Pointing {
|
||||
let self = this
|
||||
this.mousemoveHandler = e => {
|
||||
self.blueprint.entity.mousePosition = self.getLocation(e)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ export default class MouseWheel extends Pointing {
|
||||
e.preventDefault()
|
||||
const location = self.getLocation(e)
|
||||
self.wheel(Math.sign(e.deltaY), location)
|
||||
return true
|
||||
}
|
||||
this.mouseParentWheelHandler = e => e.preventDefault()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user