C

KeyboardInputMode

An IInputMode that recognizes simple key events and invokes a registered action.
ImplementsInheritance Hierarchy

Remarks

This mode is exclusive by default.

Examples

Typically the KeyboardInputMode is installed as a child mode of a GraphEditorInputMode or GraphViewerInputMode and can be retrieved from the keyboardInputMode property.
Getting the KeyboardInputMode from its parent input mode
const keyboardInputMode = mode.keyboardInputMode
Adding a handler for a keyboard event
// Execute the command if the Insert key is pressed
graphEditorInputMode.keyboardInputMode.addKeyBinding(
  'Insert',
  ModifierKeys.NONE,
  () => {
    graphEditorInputMode.createNode(
      graphEditorInputMode.graphComponent!.viewport.center,
    )
  },
)
Adding a handler triggered by a keyboard event recognizer
// 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

Show:

Constructors

Parameters

Properties

Gets the canvas instance this mode is currently installed in or null.
readonlyfinal
Gets the installed controller.
protectedreadonlyfinal
Gets or sets the enabled state of this input mode.
Clients can use this property to disable or reenable this instance. This will set the enabled property of the installed controller so a disabled instance should never try to acquire the input mutex.

Examples

Disabling the KeyboardInputMode on its parent input mode
mode.keyboardInputMode.enabled = false

See Also

Developer's Guide
Gets or sets a value indicating whether this mode will be the only one running when it has the mutex.

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.

final
Retrieves the IInputModeContext this mode has been installed in.
The value will be null if this mode is currently not installed.
protectedreadonlyfinal
Gets the priority of this input mode.
The priority will influence the order in which the modes will be installed into the CanvasComponent. The lower the priority value, the earlier it will be installed. If two modes are using the same priority value, the first one to be registered will be installed earlier.
final

Methods

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: Command
The command to register handlers with.
executedHandler: function(ExecuteCommandArgs): void
The handler for the execution.
canExecuteHandler?: function(CanExecuteCommandArgs): void
The handler that determines whether the command can be executed, null if the command can always be executed.

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
Adds an action for a specific key down event to this mode.
The action will not be invoked if this instance is disabled or inactive.

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 modifiers are handled separately.
modifiers: ModifierKeys
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.

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

Adding an action for a keyboard event
// 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
Adds 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.

Parameters

recognizer: function(EventArgs, unknown): boolean
An event recognizer that will be fed with all key events.
action: function
The action to invoke if the recognizer matches an event.

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
Will be called to unconditionally cancel all ongoing edits.

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()
}
Installs 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
Called after cancel has been called.

Can be overridden in subclasses to perform additional actions after the mode has been canceled.

This implementation does nothing.

protected
Called after the active property of the installed ConcurrencyController has been set to true.

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.

protected
Called after the active property of the installed ConcurrencyController has been set to false.

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.

protected
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.

protected
Triggers the text-input event.
protected

Parameters

evt: TextEventArgs
The event arguments.
Overridden to only return true if this instance does not currently have the input mutex.

Return Value

boolean
true iff this instance does not own the mutex.
Uninstalls 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.

Events

Occurs when text was input, but the event was not handled or did not match a command.
This event can be used to detect when the user started typing and will provide the text that was input, so far.

Properties of

TextEventArgs
context: IInputModeContext
Gets the context for the current event.
text: string
Gets the text that was or will be edited.