EditorCommand
public protocol EditorCommand : AnyObject
Describes a command that can be executed on EditorView
. A command may be invoked directly on the editor
by providing an instance.
However, in a typical usage scenario, these should be invoked via EditorCommandExecutor
which manages all the EditorView
s in the
view including the ones that are contained in the attachments.
-
Identifies a command. This value is used to maintain unique registrations of commands in an Editor. Adding a command with the same name as one registered already would end up replacing the previously registered command with the same name.
Declaration
Swift
var name: CommandName { get }
-
canExecute(on:
Default implementation) Determines if the current command can be executed on the given
EditorView
. When a command is executed usingEditorCommandExecutor
, it ensures that only the commands returningtrue
for the activeEditorView
are executed when invoked. Defaults totrue
.Default Implementation
Declaration
Swift
func canExecute(on editor: EditorView) -> Bool
Parameters
editor
EditorView
to execute the command on. -
Execute the command on the given
EditorView
. You may useselectedRange
property ofEditorView
if the command operates on the selected text only. for e.g. a command to make selected text bold.Declaration
Swift
func execute(on editor: EditorView)
Parameters
editor
EditorView
to execute the command on.