Docsv3.20.2
Back to API Reference
Class

TextCommand

abstract

A command of the text context menu: its label, when it applies, and what it does to the field that presents it. The field lists its commands in Commands; the system menu shows the applicable ones in that order, and the Unity-UI menu shows each on the item bound to it. Derive from it and implement Execute for a command of your own.

Remarks

The field passes its own state with every call, so one instance can serve many fields. IsApplicable is asked every time the menu is presented or re-anchored, and again when the user picks the command from a menu, a TextCommandButton or a shortcut; Execute runs on the main thread only while the command applies, against the field's state at that moment.

Derived Types(11)

Types that inherit from TextCommand.

C
ClearFormattingCommand
Strips every style from the selection; at a caret, the next typed text is plain. Applies while the field is editable.
C
CopyCommand
Copies the selection to the clipboard in every format the field's clipboard adapters produce. Applies while the selection may be copied.
C
CutCommand
Cuts the selection to the clipboard. Applies while the field is editable and its selection may be copied.
C
PasteCommand
Pastes the clipboard over the selection through the field's paste pipeline — adapters, filters, media handlers. Applies while the field is editable and the clipboard holds content.
C
PastePlainCommand
Pastes the clipboard's plain text, leaving its formatting behind. Applies while the field is editable and a paste would take formatting from the clipboard — so it never repeats [[PasteCommand]].
C
RedoCommand
Redoes the field's last undone edit. Applies while the field is editable and has an edit to redo.
C
SearchWebCommand
Opens the address its search URL builds from the selected text in the default browser — a web search by default; a dictionary, a translator or a map work the same way under their own titles. Applies while the selection may be copied; a selection longer than 1000 characters goes in as its first 1000.
C
SelectAllCommand
Selects the whole text. Applies while the text is not empty and not already selected whole; the menu stays up over the new selection.
C
ShareCommand
Hands the selected text to the system share sheet: Android's share chooser, iOS's activity sheet, which on iPad points at the selection. Applies on Android and iOS players while the selection may be copied.
C
ToggleStyleCommand
Toggles one of the field's own styles on the selection, or as the typing style at a caret, in that style's markup syntax — bold unless another style is chosen. Applies while the field is editable and carries a style the source can toggle; its default title is the style's own label.
C
UndoCommand
Undoes the field's last edit. Applies while the field is editable and has an edit to undo.
public string Title{ get }

Label of the command's menu entry in the current language: the title set in the inspector, or DefaultTitle while none is set or a localized one is still loading.

protected string DefaultTitle{ get }

Label shown while no title is set — by default the type name in sentence case without its Command suffix, so SearchWebCommand reads "Search web".

public bool KeepsMenu{ get }

Whether invoking the command leaves the menu up, presented again over the selection the command leaves, as select-all does on the touch platforms. False by default: a command takes the menu down, and on Android a touch menu's selection with it, collapsed at its focus as Android's text view leaves it.

[ctor]protected TextCommand()

Creates a command that shows its DefaultTitle.

[ctor]protected TextCommand()

Creates a command titled title in every language, editable in the inspector.

public virtual bool IsApplicable()

Whether the command applies to the field's current state. A menu hides or disables a command that does not apply, and a command runs only while it applies.

public virtual bool IsActive()

Whether the command's effect is on at the field's selection, for a control that shows it as pressed — a style toggle reports whether its style is active. False for a command that toggles nothing.

public abstract void Execute()

Runs the command against the field's current state, to which it applies (IsApplicable).

public virtual bool Matches()

Whether command is this command, as a menu item bound to this command matches the field's (Command): by default, a command of this type or one derived from it. The title plays no part; a command whose settings decide its effect compares them too, as a style toggle compares its style.