Remarks
Examples
KeyboardInputMode is installed as a child mode of a GraphEditorInputMode or GraphViewerInputMode and can be retrieved from the keyboardInputMode property.const keyboardInputMode = mode.keyboardInputMode// Execute the command if the Insert key is pressed
graphEditorInputMode.keyboardInputMode.addKeyBinding(
'Insert',
ModifierKeys.NONE,
() => {
graphEditorInputMode.createNode(
graphEditorInputMode.graphComponent!.viewport.center,
)
},
)// Fit graph into viewport if the Enter key is pressed
graphEditorInputMode.keyboardInputMode.addRecognizerBinding(
(evt) => evt instanceof KeyEventArgs && evt.key === 'Enter',
() => graphComponent.fitGraphBounds(),
)See Also
Developer's Guide
Members
Constructors
Properties
Gets the canvas instance this mode is currently installed in or null.
null.Gets the installed controller.
Examples
mode.keyboardInputMode.enabled = falseSee Also
Developer's Guide
The value of this property will be delegated to the exclusive property of the controller.
If this mode is marked as exclusive and has the mutex, all other modes added to the same MultiplexingInputMode will be deactivated. Otherwise, it will always run concurrently with all other modes.
Retrieves the IInputModeContext this mode has been installed in.
null if this mode is currently not installed.Implements
IInputMode.priorityMethods
Adds a Command and associated execution handlers to this instance.
When a command is already registered (which is the case for most commands), the new binding is executed first, followed by the previously registered bindings. The built-in binding is executed last. To prevent execution of earlier registrations, let the executedHandler set handled on the ExecuteCommandArgs to true.
The command will not be allowed to execute if this mode is disabled or inactive.
Parameters
- command: Commandconversion
- The command to register handlers with.
- executedHandler: function(ExecuteCommandArgs): void
- The handler for the execution.Function signature for a callback that executes a given Command for the given parameter set in the
args.Parameters- args: ExecuteCommandArgs
- The arguments which contain the command and the optional parameter. Handler implementations have to set handled to
trueto indicate that the action was handled and executed successfully by this handler. The list of execution handlers will be traversed for all handlers until the first handler sets handled totrue.
- canExecuteHandler?: function(CanExecuteCommandArgs): void
- The handler that determines whether the
commandcan be executed,nullif the command can always be executed.Function signature for a callback that determines whether a given Command can be executed for the given parameter set in theargs.Parameters- args: CanExecuteCommandArgs
- The arguments which contain the command and the optional parameter. Handler implementations have to set canExecute to
trueto indicate that the command can be executed. Handler implementations have to set handledtrueto indicate that the action was handled.
Return Value
- KeyboardInputModeBinding
- A token for the newly created command binding that can be used to later remove this binding from this instance again.
See Also
Developer's Guide
Parameters
- type: string
- A string which represents the type of the event to register as listed in events.
- listener: function(evt:EventArgs, sender:this): void
- The function which will be invoked when the event is raised.
- options?: ListenerOptions
- Options which specify how the listener will be invoked.
Adds an action for a specific key down event to this mode.
Parameters
- key: string
- The key that should be recognized. The value of a key corresponds to KeyboardEvent.key. It is treated as case-insensitive and the
modifiersare handled separately. - modifiers: ModifierKeysconversion
- The modifiers that should be recognized when the key is pressed.
- action: function
- The action that will be invoked if the given key down event is recognized.Encapsulates a method that has no parameters and does not return a value.
Return Value
- KeyboardInputModeBinding
- A token for the newly created command binding that can be used to later remove this binding from this instance again.
Examples
// Execute the command if the Insert key is pressed
graphEditorInputMode.keyboardInputMode.addKeyBinding(
'Insert',
ModifierKeys.NONE,
() => {
graphEditorInputMode.createNode(
graphEditorInputMode.graphComponent!.viewport.center,
)
},
)See Also
Developer's Guide
addRecognizerBinding
(recognizer: function(EventArgs, unknown): boolean, action: function): KeyboardInputModeBindingAdds a given action to this instance that will be triggered if the given event recognizer recognizes a key event that has been triggered by the canvasComponent.
addRecognizerBinding
(recognizer: function(EventArgs, unknown): boolean, action: function): KeyboardInputModeBindingaction to this instance that will be triggered if the given event recognizer recognizes a key event that has been triggered by the canvasComponent.Parameters
- recognizer: function(EventArgs, unknown): boolean
- An event recognizer that will be fed with all key events.A callback that recognizes events.Given a sender and an event argument, delegates decide whether the event is treated as a match depending on the context.Parameters
- evt: EventArgs
- The arguments of the event to be decided to handle.
- eventSource: unknown
- The source of the event.
Return Value- boolean
trueif theevtis considered to be handled.
- action: function
- The action to invoke if the recognizer matches an event.Encapsulates a method that has no parameters and does not return a value.
Return Value
- KeyboardInputModeBinding
- A token for the newly created command binding that can be used to later remove this binding from this instance again.
See Also
Developer's Guide
This will be called prior to the uninstalling of this instance and when other input modes temporarily acquire the mutex.
In order to stop an active input mode manually, client code should use the following idiom:
if (!mode.tryStop()) {
mode.cancel()
}Implements
IInputMode.cancelInstalls this mode into the given context that is provided by the canvas.
In general a mode can only be installed into a single canvas at all times.
This method is called to initialize this instance. Subclasses should override this method to register the corresponding event handler delegates for the various input events they need to register with.
Overriding implementations should call the base implementation first.
Parameters
- context: IInputModeContext
- The context that this instance shall be installed into. The same instance will be passed to this instance during uninstall. A reference to the context may be kept and queried during the time the mode is installed.
- controller: ConcurrencyController
- The controller for this mode.
See Also
API
- uninstall
Implements
IInputMode.installCalled after cancel has been called.
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
Enables the registered commands and can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
Disables the registered commands and can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
Called after tryStop has been called.
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
Triggers the text-input event.
Parameters
- evt: TextEventArgs
- The event arguments.
Parameters
- type: string
- A string which represents the type of the event to register as listed in events.
- listener: function(evt:EventArgs, sender:this): void
- The function which will be invoked when the event is raised.
- options?: ListenerOptions
- Options which specify how the listener will be invoked.
Overridden to only return true if this instance does not currently have the input mutex.
true if this instance does not currently have the input mutex.Return Value
- boolean
trueiff this instance does not own the mutex.
Implements
IInputMode.tryStopUninstalls this mode from the given context.
This code should clean up all changes made to the canvas in the install method. After a mode has been uninstalled it can be installed again into the same or another canvas.
Overriding implementations should call the base implementation after their own code.
Parameters
- context: IInputModeContext
- The context to deregister from. This is the same instance that had been passed to install during installation.
Implements
IInputMode.uninstallEvents
Occurs when text was input, but the event was not handled or did not match a command.
- context: IInputModeContextfinal
- Gets the context for the current event.
- text: stringfinal
- Gets the text that was or will be edited.