Skip to main content

QuillOperation

Namespace: Wisej.Web.Ext.QuillJS

Assembly: Wisej.Web.Ext.QuillJS (4.1.0.0)

Represents a single operation in a Delta.

public class QuillOperation

An operation is either an insert (Insert), a delete (Delete) or a retain (Retain); only one of the three should be set. Attributes applies to insert and retain operations.

Constructors​

Instance member QuillOperation()​

Initializes a new instance of QuillOperation.

Properties​

Instance member Attributes​

Dictionary<String, Object>: Returns or sets the formatting attributes, or null.

The keys are QuillJS format names (see Formats) and the values are the format values, i.e. true for "bold", "#ff0000" for "color" or 2 for "header".

Example:

Creating a red, bold insert operation:

var op = new QuillOperation
{
Insert = "Warning",
Attributes = new Dictionary<string, object>
{
{ QuillFormat.Formats.Bold, true },
{ QuillFormat.Formats.Color, "#ff0000" }
}
};

Instance member Delete​

Nullable<Int32>: Returns or sets the number of characters to delete, or null if this is not a delete operation.

Instance member Insert​

String: Returns or sets the text to insert.

Instance member Retain​

Nullable<Int32>: Returns or sets the number of characters to retain, or null if this is not a retain operation.

Methods​

Instance member Length()​

Returns the length of this operation.

Returns: Int32. The length of the inserted text, or the number of deleted or retained characters, or 0 if nothing is set.

Example:

Counting the characters inserted by a delta:

int inserted = delta.Operations.Where(op => op.Insert != null).Sum(op => op.Length());

Instance member Slice(start, end)​

Creates a slice of this operation.

ParameterTypeDescription
start optionalInt32The zero-based starting position within the operation. The default is 0.
end optionalNullable<Int32>The position where the slice ends (exclusive), or null to slice to the end of the operation.

Returns: QuillOperation. A new QuillOperation of the same kind with a copy of the Attributes.

Example:

Taking the first 3 characters of an insert operation:

var op = new QuillOperation { Insert = "Hello" };
var first = op.Slice(0, 3); // Insert = "Hel"