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.
- C#
- VB.NET
public class QuillDelta : IWisejSerializable
Public Class QuillDelta
Inherits 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
QuillDelta()
Initializes a new empty instance of the QuillDelta class.
QuillDelta(operations)
Initializes a new instance of the QuillDelta class with the specified operations.
| Name | Type | Description |
|---|---|---|
| operations | IEnumerable<QuillOperation> | The initial operations to add to the delta. |
Properties
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
Compose(other)
Composes this Delta with another Delta.
| Parameter | Type | Description |
|---|---|---|
| other | QuillDelta | The 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);
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());
Insert(text)
Adds an insert operation to this delta.
| Parameter | Type | Description |
|---|---|---|
| text | String | The 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);
Insert(text, attributes)
Adds an insert operation with the specified formatting attributes to this delta.
| Parameter | Type | Description |
|---|---|---|
| text | String | The text to insert. |
| attributes | Dictionary<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);
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.");
Retain(length)
Adds a retain operation that skips the specified number of characters without modifying them.
| Parameter | Type | Description |
|---|---|---|
| length | Int32 | The number of characters to retain. |
Throws:
- ArgumentException length is less than or equal to 0.
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);
Retain(length, attributes)
Adds a retain operation that applies the specified formatting attributes to the retained characters.
| Parameter | Type | Description |
|---|---|---|
| length | Int32 | The number of characters to retain. |
| attributes | Dictionary<String, Object> | The attributes to apply to the retained characters. Use a null value to remove a format. |
Throws:
- ArgumentException length is less than or equal to 0.
- ArgumentNullException attributes is null.
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);
Slice(start, end)
Returns a new Delta containing the operations between the start and end positions.
| Parameter | Type | Description |
|---|---|---|
| start | Int32 | The zero-based starting position. The default is 0. |
| end | Nullable<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
| Name | Description |
|---|---|
| IWisejSerializable |