textarea in the CanvasComponent to let the user edit a text.- I
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.textEditorInputModeSee Also
- The CSS styling options for the editor container are presented in detail in the section CSS Transition or Animation for the Input Element .
Developer's Guide
Members
Constructors
Creates a new instance using a default text box or the provided editor.
Parameters
- editorContainer?: HTMLDivElement
- The editor to use as the text editor. If none is provided a default text editor will be used.
See Also
Properties
Gets or sets the anchor of the text box.
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
}
},
)See Also
Developer's Guide
Gets or sets a value indicating whether to automatically flip the orientation of the text box if the upVector actually points downwards.
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.
truefalse 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.
Property Value
See Also
Gets the installed controller.
Gets the HTMLDivElement that contains the text editor.
HTMLDivElement that contains the text editor.Property Value
HTMLDivElement 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
Developer's Guide
API
- createEditorContainer
Examples
mode.editLabelInputMode.textEditorInputMode.enabled = falseThe 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.
Property Value
See Also
Gets or sets the location of the text box in world coordinates.
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
Developer's Guide
Retrieves the IInputModeContext this mode has been installed in.
null if this mode is currently not installed.Implements
IInputMode.priorityGets or sets a value indicating whether the text box should be rotated with the upVector.
false (the default), the text box will always be horizontal.See Also
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.
Gets or sets the margins to use around the editorContainer when it comes near to the viewport borders and needs to be adjusted.
Gets or sets the textBoxPlacementPolicy to use when the editorContainer isn't completely visible in the current viewport.
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.
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
Developer's Guide
API
- rotateTextBox
Methods
Adjusts the position of the text box in the CanvasComponent.
Adjusts the size of the text box in the editorContainer.
Calculates the maximum size for this instance.
The result is passed to adjustSize.
This implementation makes sure the textbox does not exceed the bounds of the canvas.
Return Value
- Size
- The maximum size for the textbox.
See Also
API
- adjustSize
Implements
IInputMode.cancelCreates the default editor and it's container HTMLDivElement.
HTMLDivElement.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
Return Value
- HTMLDivElement
- The
HTMLDivElementthat will be placed in the CanvasComponent for editing the text.
Starts interactive text editing.
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.
Return Value
- Promise<string>
- A Promise that will fulfill with the edited text or fulfill with
nullif 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.
true.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
Implements
IInputMode.installInstalls the editorContainer in the canvas and puts focus into it.
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.
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
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.
Raises the editing-started event.
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.
Raises the text-edited event.
falseReturn Value
- boolean
trueif and only if the editing has been stopped or there was no edit in progress
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 if the editing has not been finished.
Properties of
TextEventArgs- context: IInputModeContext
- Gets the context for the current event.
- text: string
- Gets the text that was or will be edited.
See Also
Developer's Guide
Occurs when text editing is started.
Properties of
TextEventArgs- context: IInputModeContext
- Gets the context for the current event.
- text: string
- Gets the text that was or will be edited.
See Also
Developer's Guide
Occurs when the editor's text should be changed.
Properties of
TextEventArgs- context: IInputModeContext
- Gets the context for the current event.
- text: string
- Gets the text that was or will be edited.
Occurs once the text has been edited.
Properties of
TextEventArgs- context: IInputModeContext
- Gets the context for the current event.
- text: string
- Gets the text that was or will be edited.
See Also
Developer's Guide