mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-28 19:54:43 +08:00
Text edit input behavior fixed
This commit is contained in:
@@ -34,9 +34,10 @@ export default class IInput {
|
||||
constructor(target, blueprint, options) {
|
||||
this.#target = target
|
||||
this.#blueprint = blueprint
|
||||
options.consumeEvent ??= false
|
||||
options.listenOnFocus ??= false
|
||||
options.unlistenOnTextEdit ??= false
|
||||
this.options = options
|
||||
this.options.listenOnFocus = this.options?.listenOnFocus ?? false
|
||||
this.options.unlistenOnTextEdit = this.options?.unlistenOnTextEdit ?? true
|
||||
let self = this
|
||||
this.listenHandler = _ => self.listenEvents()
|
||||
this.unlistenHandler = _ => self.unlistenEvents()
|
||||
@@ -44,7 +45,7 @@ export default class IInput {
|
||||
this.blueprint.addEventListener(Configuration.focusEventName.begin, this.listenHandler)
|
||||
this.blueprint.addEventListener(Configuration.focusEventName.end, this.unlistenHandler)
|
||||
}
|
||||
if (options?.unlistenOnTextEdit ?? false) {
|
||||
if (this.options.unlistenOnTextEdit) {
|
||||
this.blueprint.addEventListener(Configuration.editTextEventName.begin, this.unlistenHandler)
|
||||
this.blueprint.addEventListener(Configuration.editTextEventName.end, this.listenHandler)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ export default class Copy extends IInput {
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus = true
|
||||
options.unlistenOnTextEdit = true
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
|
||||
@@ -11,6 +11,7 @@ export default class Paste extends IInput {
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus = true
|
||||
options.unlistenOnTextEdit = true
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
|
||||
@@ -11,8 +11,10 @@ export default class IKeyboardShortcut extends IInput {
|
||||
#activationKeys
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus = true
|
||||
options.activateAnyKey ??= false
|
||||
options.activationKeys ??= []
|
||||
options.listenOnFocus ??= true
|
||||
options.unlistenOnTextEdit ??= true
|
||||
if (!(options.activationKeys instanceof Array)) {
|
||||
options.activationKeys = [options.activationKeys]
|
||||
}
|
||||
@@ -42,12 +44,14 @@ export default class IKeyboardShortcut extends IInput {
|
||||
/** @param {KeyboardEvent} e */
|
||||
this.keyDownHandler = e => {
|
||||
if (
|
||||
self.#activationKeys.some(keyEntry =>
|
||||
this.options.activateAnyKey
|
||||
|| self.#activationKeys.some(keyEntry =>
|
||||
wantsShift(keyEntry) == e.shiftKey
|
||||
&& wantsCtrl(keyEntry) == e.ctrlKey
|
||||
&& wantsAlt(keyEntry) == e.altKey
|
||||
&& Configuration.Keys[keyEntry.Key] == e.code
|
||||
)) {
|
||||
)
|
||||
) {
|
||||
if (options.consumeEvent) {
|
||||
e.stopImmediatePropagation()
|
||||
}
|
||||
@@ -60,13 +64,15 @@ export default class IKeyboardShortcut extends IInput {
|
||||
/** @param {KeyboardEvent} e */
|
||||
this.keyUpHandler = e => {
|
||||
if (
|
||||
self.#activationKeys.some(keyEntry =>
|
||||
this.options.activateAnyKey
|
||||
|| self.#activationKeys.some(keyEntry =>
|
||||
keyEntry.bShift && e.key == "Shift"
|
||||
|| keyEntry.bCtrl && e.key == "Control"
|
||||
|| keyEntry.bAlt && e.key == "Alt"
|
||||
|| keyEntry.bCmd && e.key == "Meta"
|
||||
|| Configuration.Keys[keyEntry.Key] == e.code
|
||||
)) {
|
||||
)
|
||||
) {
|
||||
if (options.consumeEvent) {
|
||||
e.stopImmediatePropagation()
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ export default class KeyboardCanc extends IKeyboardShortcut {
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: Configuration.deleteNodesKeyboardKey
|
||||
}
|
||||
options.activationKeys = Configuration.deleteNodesKeyboardKey
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@ export default class KeyboardEnableZoom extends IKeyboardShortcut {
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: Configuration.enableZoomIn
|
||||
}
|
||||
options.activationKeys = Configuration.enableZoomIn
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,7 @@ export default class KeyboardSelectAll extends IKeyboardShortcut {
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: Configuration.selectAllKeyboardKey
|
||||
}
|
||||
options.activationKeys = Configuration.selectAllKeyboardKey
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
|
||||
started = false
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
options.unlistenOnTextEdit
|
||||
constructor(target, blueprint, options = {}) {
|
||||
super(target, blueprint, options)
|
||||
this.clickButton = options?.clickButton ?? 0
|
||||
this.exitAnyButton = options?.exitAnyButton ?? true
|
||||
|
||||
@@ -87,7 +87,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
pin.removeEventListener("mouseenter", this.#mouseenterHandler)
|
||||
pin.removeEventListener("mouseleave", this.#mouseleaveHandler)
|
||||
})
|
||||
if (this.enteredPin) {
|
||||
if (this.enteredPin && this.linkValid) {
|
||||
this.blueprint.addGraphElement(this.link)
|
||||
this.link.destinationPin = this.enteredPin
|
||||
this.link.setLinkMessage(null)
|
||||
|
||||
16
js/input/mouse/MouseIgnore.js
Normal file
16
js/input/mouse/MouseIgnore.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import IMouseClickDrag from "./IMouseClickDrag";
|
||||
|
||||
/**
|
||||
* @typedef {import("../../element/PinElement").default} PinElement
|
||||
*/
|
||||
|
||||
/**
|
||||
* @extends IMouseClickDrag<PinElement>
|
||||
*/
|
||||
export default class MouseIgnore extends IMouseClickDrag {
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.consumeEvent = true
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user