EditArray Class
Merges multiple edit operations to create a single operation.
Assembly: Microsoft.VisualStudio.Package.LanguageService.14.0 (in Microsoft.VisualStudio.Package.LanguageService.14.0.dll)
| Name | Description | |
|---|---|---|
![]() | EditArray(Source, IVsTextView, Boolean, String) | Initializes a new instance of the EditArray class using a Source object and an IVsTextView object. |
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of edit operations represented in the EditArray object. |
![]() | Source | Gets the Source object associated with this EditArray object. |
![]() | TextView | Gets the IVsTextView object associated with this EditArray object. |
| Name | Description | |
|---|---|---|
![]() | Add(EditSpan) | Adds the specified EditSpan object to the array of edit operations. |
![]() | ApplyEdits() | Applies all edit operations that have been accumulated. |
![]() | Dispose() | Disposes the EditArray object and its resources. |
![]() | Equals(Object) | (Inherited from Object.) |
![]() | Finalize() | Tears down the EditArray object.(Overrides Object.Finalize().) |
![]() | GetEnumerator() | Gets a default enumerator for the edit operations. |
![]() | GetHashCode() | (Inherited from Object.) |
![]() | GetType() | (Inherited from Object.) |
![]() | MemberwiseClone() | (Inherited from Object.) |
![]() | ToString() | Converts the array of edit operations to a formatted string.(Overrides Object.ToString().) |
This class wraps multiple edit operations to create a single operation that can be undone when updating a source file. This efficiency is obtained by merging adjacent edit operations. In addition, this class ensures that existing markers such as breakpoints and bookmarks are not lost when edit operations are applied to the source file.
This class is typically used to wrap a formatting event, where multiple lines of source can be changed in what seems a single operation to the user.
To create a single edit event, this class uses the CompoundViewAction class if an IVsTextView object is available; otherwise, the CompoundAction class is used.
In the case of an EditArray object, an edit operation is either an insertion or a replacement. A deletion is a special case of a replacement where the replacement string is empty.
Notes to Implementers:
This class contains all the functionality needed to merge and apply multiple edits. There is no need to derive from this class.
Notes to Callers:
To wrap multiple edit operations, instantiate a new EditArray object then call the Add method one or more times with the span being affected. Finally, call the ApplyEdits method to apply all the edits at once.
Here is an example of how to replace or insert the first line of a document (which might, for example, contain document property information). Although this demonstrates a single edit operation, the example can be readily expanded to support multiple lines and multiple edit operations.
using Microsoft.VisualStudio.Package; namespace MyLanguagePackage { class MyLanguageService : LanguageService { void SetPropertyValue(string propertyName, string propertyValue) { int lineNumberToReplace = 0; string propertyLine = String.Format("//!{0} = {1}", propertyName, propertyValue); string documentLine = src.GetLine(lineNumberToReplace); bool fInsertLine = true; if (documentLine.IndexOf("//!") == 0)) { fInsertLine = false; } // Now insert or replace the line EditArray editArray = new EditArray(this.LastActiveTextView, true, "Update property"); if (editArray != null) { TextSpan span = new TextSpan(); if (fInsertLine) { span.iStartLine = lineNumberToReplace; span.iStartIndex = 0; span.IEndLine = lineNumberToReplace; span.iEndIndex = 0; propertyLine += "\n"; } else { int lineLength = 0; src.GetLines().GetLengthOfLine(lineNumberToReplace,out lineLength); span.iStartLine = lineNumberToReplace; span.iStartIndex = 0; span.iEndLine = lineNumberToReplace; span.iEndIndex = lineLength; } editArray.Add(new EditSpan(span, propertyLine)); // Multiple Adds can be done here before ApplyEdits editArray.ApplyEdits(); } } } }
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


