QuillOperation
Namespace: Wisej.Web.Ext.QuillJS
Assembly: Wisej.Web.Ext.QuillJS (4.1.0.0)
Represents a single operation in a Delta.
- C#
- VB.NET
public class QuillOperation
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
QuillOperation()
Initializes a new instance of QuillOperation.
Properties
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" }
}
};
Delete
Nullable<Int32>: Returns or sets the number of characters to delete, or null if this is not a delete operation.
Insert
String: Returns or sets the text to insert.
Retain
Nullable<Int32>: Returns or sets the number of characters to retain, or null if this is not a retain operation.
Methods
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());
Slice(start, end)
Creates a slice of this operation.
| Parameter | Type | Description |
|---|---|---|
| start | Int32 | The zero-based starting position within the operation. The default is 0. |
| end | Nullable<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"