Skip to main content

QuillDelta

Namespace: Wisej.Web.Ext.QuillJS

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

Represents a Delta object that describes content and formatting changes in the QuillJS editor.

public class QuillDelta : IWisejSerializable

A delta is a list of QuillOperation items (insert, retain or delete). A delta that contains only insert operations describes a whole document and can be loaded with SetDeltaAsync; a delta that also contains retain and delete operations describes a change and can be applied with UpdateContent. The delta is serialized to the client as {"ops":[...]}.

Constructors​

Instance member QuillDelta()​

Initializes a new empty instance of the QuillDelta class.

Instance member QuillDelta(operations)​

Initializes a new instance of the QuillDelta class with the specified operations.

NameTypeDescription
operationsIEnumerable<QuillOperation>The initial operations to add to the delta.

Properties​

Instance member Operations​

List<QuillOperation>: Returns the list of operations in this delta.

The list can be modified directly or through Insert and Retain.

Example:

Adding a delete operation, which doesn't have a helper method:

var delta = new QuillDelta();
delta.Retain(10);
delta.Operations.Add(new QuillOperation { Delete = 5 });
this.quillJSEditor1.UpdateContent(delta);

Methods​

Instance member Compose(other)​

Composes this Delta with another Delta.

ParameterTypeDescription
otherQuillDeltaThe delta to compose with this delta.

Returns: QuillDelta. A new QuillDelta combining the operations of both deltas; this instance is not modified.

This is a simplified implementation that pairs whole operations and merges their attributes; it doesn't split operations of different lengths like the QuillJS compose() function does.

Example:

Combining a document with a change that makes the first operation bold:

var document = new QuillDelta();
document.Insert("Hello");
document.Insert(" World\n");

var bold = new QuillDelta();
bold.Retain(5, new Dictionary<string, object> { { "bold", true } });

var result = document.Compose(bold);

Instance member GetText()​

Returns the plain text content of this Delta.

Returns: String. The concatenation of the text of all the insert operations.

Example:

Reading the plain text of the editor content:

var delta = await this.quillJSEditor1.GetDeltaAsync();
AlertBox.Show(delta.GetText());

Instance member Insert(text)​

Adds an insert operation to this delta.

ParameterTypeDescription
textStringThe text to insert.

The text is inserted at the position reached by the preceding operations. A document delta should end with a new line character ("\n").

Example:

Loading a simple document into the editor:

var delta = new QuillDelta();
delta.Insert("Meeting notes\n");
await this.quillJSEditor1.SetDeltaAsync(delta);

Instance member Insert(text, attributes)​

Adds an insert operation with the specified formatting attributes to this delta.

ParameterTypeDescription
textStringThe text to insert.
attributesDictionary<String, Object>The formatting attributes to apply to the inserted text, i.e. "bold" = true, or null.

Attribute names are the QuillJS format names listed in Formats. Line formats (i.e. "header", "list", "align") must be applied to the new line character that ends the line.

Example:

Building a document with a header and bold text:

var delta = new QuillDelta();
delta.Insert("Report");
delta.Insert("\n", new Dictionary<string, object> { { QuillFormat.Formats.Header, 1 } });
delta.Insert("Total: ");
delta.Insert("1,250", new Dictionary<string, object> { { QuillFormat.Formats.Bold, true } });
delta.Insert("\n");
await this.quillJSEditor1.SetDeltaAsync(delta);

Instance member Length()​

Returns the length of the content in this Delta.

Returns: Int32. The sum of the lengths of the insert and retain operations; delete operations count as 0.

Example:

Checking the number of characters in the editor:

var delta = await this.quillJSEditor1.GetDeltaAsync();
if (delta.Length() > 5000)
AlertBox.Show("The text is too long.");

Instance member Retain(length)​

Adds a retain operation that skips the specified number of characters without modifying them.

ParameterTypeDescription
lengthInt32The number of characters to retain.

Throws:

Example:

Inserting text after the first 10 characters of the editor content:

var delta = new QuillDelta();
delta.Retain(10);
delta.Insert("inserted text ");
this.quillJSEditor1.UpdateContent(delta);

Instance member Retain(length, attributes)​

Adds a retain operation that applies the specified formatting attributes to the retained characters.

ParameterTypeDescription
lengthInt32The number of characters to retain.
attributesDictionary<String, Object>The attributes to apply to the retained characters. Use a null value to remove a format.

Throws:

Example:

Making the first 5 characters of the editor content bold:

var delta = new QuillDelta();
delta.Retain(5, new Dictionary<string, object> { { QuillFormat.Formats.Bold, true } });
this.quillJSEditor1.UpdateContent(delta);

Instance member Slice(start, end)​

Returns a new Delta containing the operations between the start and end positions.

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

Returns: QuillDelta. A new QuillDelta; operations that span the boundaries are split.

Example:

Extracting the first 100 characters of the content with their formatting:

var delta = await this.quillJSEditor1.GetDeltaAsync();
var preview = delta.Slice(0, 100);

Implements​

NameDescription
IWisejSerializable