An IInputMode implementation that displays a textarea
in the CanvasComponent to let the user edit a text.
Remarks
Hitting escape or enter will cancel or stop editing.
This mode is exclusive by default.
The editorContainer is using the yfiles-labeleditbox
CSS class and provides additional classes for the enter and leave phase of the container.
Examples
TextEditorInputMode
is installed as child mode of an EditLabelInputMode and can be retrieved from the textEditorInputMode property.const textEditorInputMode = mode.editLabelInputMode.textEditorInputMode
Related Reading in the Developer's Guide
Type Details
- yFiles module
- view
Constructors
Creates a new instance using a default text box or the provided editor.
Parameters
A map of options to pass to the method.
- editorContainer - HTMLDivElement
- The editor to use as the text editor. If none is provided a default text editor will be used.
- priority - number
- exclusive - boolean
- A value indicating whether this mode will be the only one running when it has the mutex. This option sets the exclusive property on the created object.
- enabled - boolean
- The enabled state of this input mode. This option sets the enabled property on the created object.
- stopEditingOnCommit - boolean
- A property that determines whether the text editor should be closed on commit. This option sets the stopEditingOnCommit property on the created object.
- autoCommitOnFocusLost - boolean
- Whether the text edited should be committed or the editing should be canceled if the focus is lost. This option sets the autoCommitOnFocusLost property on the created object.
- autoFocusCanvasOnEditorClosed - boolean
- A property that determines whether this mode should try to focus the GraphComponent once the editor is closed via a keyboard gesture. This option sets the autoFocusCanvasOnEditorClosed property on the created object.
- autoStartEditing - boolean
- Whether this mode should automatically fire up the editor once it gets installed. This option sets the autoStartEditing property on the created object.
- lineBreakRecognizer - function(EventArgs, unknown):boolean
- The event recognizer that detects the key gesture for new line breaks. This option sets the lineBreakRecognizer property on the created object.
Signature Details
function(evt: EventArgs, eventSource: unknown) : boolean
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.
Returns
- boolean
true
if theevt
is considered to be handled.
- cancelRecognizer - function(EventArgs, unknown):boolean
- The event recognizer that detects when editing the text should be canceled. This option sets the cancelRecognizer property on the created object.
Signature Details
function(evt: EventArgs, eventSource: unknown) : boolean
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.
Returns
- boolean
true
if theevt
is considered to be handled.
- stopRecognizer - function(EventArgs, unknown):boolean
- The event recognizer to detect when editing the text should be stopped. This option sets the stopRecognizer property on the created object.
Signature Details
function(evt: EventArgs, eventSource: unknown) : boolean
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.
Returns
- boolean
true
if theevt
is considered to be handled.
- location - IPoint
- The location of the text box in world coordinates. This option sets the location property on the created object.
- upVector - IPoint
- The point that describes the "up"-vector that will be used to determine the orientation of the text box in the world coordinate system. This option sets the upVector property on the created object.
- anchor - IPoint
- The anchor of the text box. This option sets the anchor property on the created object.
- selectContent - boolean
- Whether the content of the text editor should be selected when the textbox gets shown. This option sets the selectContent property on the created object.
- autoFlipTextBox - boolean
- A value indicating whether to automatically flip the orientation of the text box if the upVector actually points downwards. This option sets the autoFlipTextBox property on the created object.
- rotateTextBox - boolean
- A value indicating whether the text box should be rotated with the upVector. This option sets the rotateTextBox property on the created object.
- textBoxPlacementPolicy - TextBoxPlacementPolicy
- The textBoxPlacementPolicy to use when the editorContainer isn't completely visible in the current viewport. This option sets the textBoxPlacementPolicy property on the created object.
- textBoxMargins - Insets
- The margins to use around the editorContainer when it comes near to the viewport borders and needs to be adjusted. This option sets the textBoxMargins property on the created object.
See Also
Properties
Gets or sets the anchor of the text box.
Remarks
The anchor is the point inside the coordinate system of the text box that shall coincide with the location in the world coordinate system. The X and Y values are expressed as relative width/height ratios.
If this mode is used for label editing as a sub mode of EditLabelInputMode, the value of this property is overridden by a value the EditLabelInputMode considers as best suitable for the currently edited label. It can be set, though, using the textEditorInputModeConfigurator on the EditLabelInputMode for global configurations or the textEditorInputModeConfigurator from the LabelEditingEventArgs for per-label changes.
Examples
mode.editLabelInputMode.textEditorInputModeConfigurator = (
context: IInputModeContext,
inputMode: TextEditorInputMode,
label: ILabel,
) => {
// anchor the text editor centered above the label
inputMode.anchor = new Point(0.5, 1)
// always place the editor horizontal
inputMode.upVector = new Point(0, -1)
// place the editor relative to the label's center
inputMode.location = label.layout.center
}
mode.editLabelInputMode.addEventListener(
'query-label-editing',
(evt: LabelEditingEventArgs) => {
evt.textEditorInputModeConfigurator = (
context: IInputModeContext,
inputMode: TextEditorInputMode,
label: ILabel,
) => {
// anchor the text editor centered above the label
inputMode.anchor = new Point(0.5, 1)
// always place the editor horizontal
inputMode.upVector = new Point(0, -1)
// place the editor relative to the label's center
inputMode.location = label.layout.center
}
},
)
Gets or sets a value indicating whether to automatically flip the orientation of the text box if the upVector actually points downwards.
Remarks
true
.Property Value
true
if the text box should be flipped if necessary; false
otherwise.Gets or sets a property that determines whether this mode should try to focus the GraphComponent once the editor is closed via a keyboard gesture.
Remarks
true
Gets or sets whether this mode should automatically fire up the editor once it gets installed.
Remarks
false
and set the editing flag to true
in order to start editing.Gets or sets the event recognizer that detects when editing the text should be canceled.
Remarks
Property Value
Signature Details
function(evt: EventArgs, eventSource: unknown) : boolean
Parameters
- evt - EventArgs
- The arguments of the event to be decided to handle.
- eventSource - unknown
- The source of the event.
Returns
- boolean
true
if theevt
is considered to be handled.
See Also
Gets the installed controller.
Gets or sets the current editing state of the editor.
Remarks
Gets the div
-element that contains the text editor.
Property Value
div
element that contains the editor that is displayed on top of the CanvasComponent to the user for actually editing the text. By default this element contains a single textarea
child with a CSS class of yfiles-labeleditbox
.See Also
Gets or sets the text that is displayed and edited.
Remarks
Gets or sets the enabled state of this input mode.
Remarks
Examples
mode.editLabelInputMode.textEditorInputMode.enabled = false
Gets or sets a value indicating whether this mode will be the only one running when it has the mutex.
Remarks
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.
Gets or sets the event recognizer that detects the key gesture for new line breaks.
Remarks
Property Value
Signature Details
function(evt: EventArgs, eventSource: unknown) : boolean
Parameters
- evt - EventArgs
- The arguments of the event to be decided to handle.
- eventSource - unknown
- The source of the event.
Returns
- boolean
true
if theevt
is considered to be handled.
See Also
Gets or sets the location of the text box in world coordinates.
Remarks
Examples
mode.editLabelInputMode.textEditorInputModeConfigurator = (
context: IInputModeContext,
inputMode: TextEditorInputMode,
label: ILabel,
) => {
// anchor the text editor centered above the label
inputMode.anchor = new Point(0.5, 1)
// always place the editor horizontal
inputMode.upVector = new Point(0, -1)
// place the editor relative to the label's center
inputMode.location = label.layout.center
}
mode.editLabelInputMode.addEventListener(
'query-label-editing',
(evt: LabelEditingEventArgs) => {
evt.textEditorInputModeConfigurator = (
context: IInputModeContext,
inputMode: TextEditorInputMode,
label: ILabel,
) => {
// anchor the text editor centered above the label
inputMode.anchor = new Point(0.5, 1)
// always place the editor horizontal
inputMode.upVector = new Point(0, -1)
// place the editor relative to the label's center
inputMode.location = label.layout.center
}
},
)
Retrieves the IInputModeContext this mode has been installed in.
Remarks
null
if this mode is currently not installed.Gets the priority of this input mode.
Remarks
Implements
Gets or sets a value indicating whether the text box should be rotated with the upVector.
Remarks
false
(the default), the text box will always be horizontal.Gets or sets whether the content of the text editor should be selected when the textbox gets shown.
Remarks
See Also
Gets or sets a property that determines whether the text editor should be closed on commit.
Remarks
If set to false
, the text editor is kept open after commit and editing has to be stopped by the caller. This allows EditLabelInputMode to keep the editor open if label text validation fails. EditLabelInputMode always stops editing after successful validation.
If set to true
, the label editor is closed on commit even if label text validation fails. The label text is not changed when the editor is closed with invalid text.
The default value is false
.
Gets or sets the event recognizer to detect when editing the text should be stopped.
Remarks
Property Value
Signature Details
function(evt: EventArgs, eventSource: unknown) : boolean
Parameters
- evt - EventArgs
- The arguments of the event to be decided to handle.
- eventSource - unknown
- The source of the event.
Returns
- boolean
true
if theevt
is considered to be handled.
See Also
Gets or sets the margins to use around the editorContainer when it comes near to the viewport borders and needs to be adjusted.
Remarks
Gets or sets the textBoxPlacementPolicy to use when the editorContainer isn't completely visible in the current viewport.
Remarks
Gets or sets the point that describes the "up"-vector that will be used to determine the orientation of the text box in the world coordinate system.
Remarks
The default is 0, -1
.
If this mode is used for label editing as a sub mode of EditLabelInputMode, the value of this property is overridden by a value the EditLabelInputMode considers as best suitable for the currently edited label. It can be set, though, using the textEditorInputModeConfigurator on the EditLabelInputMode for global configurations or the textEditorInputModeConfigurator from the LabelEditingEventArgs for per-label changes.
Examples
mode.editLabelInputMode.textEditorInputModeConfigurator = (
context: IInputModeContext,
inputMode: TextEditorInputMode,
label: ILabel,
) => {
// anchor the text editor centered above the label
inputMode.anchor = new Point(0.5, 1)
// always place the editor horizontal
inputMode.upVector = new Point(0, -1)
// place the editor relative to the label's center
inputMode.location = label.layout.center
}
mode.editLabelInputMode.addEventListener(
'query-label-editing',
(evt: LabelEditingEventArgs) => {
evt.textEditorInputModeConfigurator = (
context: IInputModeContext,
inputMode: TextEditorInputMode,
label: ILabel,
) => {
// anchor the text editor centered above the label
inputMode.anchor = new Point(0.5, 1)
// always place the editor horizontal
inputMode.upVector = new Point(0, -1)
// place the editor relative to the label's center
inputMode.location = label.layout.center
}
},
)
See Also
Methods
Adjusts the position of the text box in the CanvasComponent.
Adjusts the size of the text box in the editorContainer.
Parameters
A map of options to pass to the method.
- maxSize - Size
- The suggested maximum size to use.
Calculates the maximum size for this instance.
Remarks
The result is passed to adjustSize.
This implementation makes sure the textbox does not exceed the bounds of the canvas.
Returns
- ↪Size
- The maximum size for the textbox.
See Also
Cancels editing of the text box.
Implements
Creates the default editor and it's container div element.
Remarks
This is called when no editor was provided to the constructor and populates editorContainer lazily on demand.
If custom code overrides this factory method to provide a custom editor, the following methods might need adjustment, too:
- editorText - alternatively use the editor-text-changed event.
- adjustSize
- adjustPosition
Returns
- ↪HTMLDivElement
- The div that will be placed in the CanvasComponent for editing the text.
Starts interactive text editing.
Remarks
The input box is not closed automatically afterward such that it can be kept open after failed validation, for example.
To close the input box afterward, either call tryStop or set stopEditingOnCommit to automatically close it after committing the gesture.
Returns
- ↪Promise<string>
- A Promise that will fulfill with the edited text or fulfill with
null
if editing is cancelled.
Adjusts the viewport of the CanvasComponent such that the text box is in the visible area.
Helper method called by installTextBox that sets the initial caret location and selects the text.
Remarks
true
.Installs this mode into the given context that is provided by the canvas.
Remarks
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
A map of options to pass to the method.
- 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
Implements
Installs the editorContainer in the canvas and puts focus into it.
Remarks
Called after cancel has been called.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
Called after the active property of the installed ConcurrencyController has been set to true
.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
Called after the active property of the installed ConcurrencyController has been set to false
.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
Raises the editing-canceled event.
Parameters
A map of options to pass to the method.
- evt - TextEventArgs
- The event argument
Raises the editing-started event.
Parameters
A map of options to pass to the method.
- evt - TextEventArgs
- The event argument.
Called when editing is stopped.
Remarks
Called after tryStop has been called.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
Raises the text-edited event.
Parameters
A map of options to pass to the method.
- evt - TextEventArgs
- The event arguments.
Will be called to request a stop of the current editing progress.
Remarks
false
Returns
- ↪boolean
true
if and only if the editing has been stopped or there was no edit in progress
See Also
Implements
Uninstalls this mode from the given context.
Remarks
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
A map of options to pass to the method.
- context - IInputModeContext
- The context to deregister from. This is the same instance that had been passed to install during installation.
Implements
Events
Occurs if the editing has not been finished.
Occurs when text editing is started.
Occurs when the editor's text should be changed.
Remarks
Occurs once the text has been edited.