本文整理汇总了C#中IDocument.OpenUndoGroup方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.OpenUndoGroup方法的具体用法?C# IDocument.OpenUndoGroup怎么用?C# IDocument.OpenUndoGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.OpenUndoGroup方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SortLines
public void SortLines(IDocument document, int startLine, int endLine, StringComparer comparer, bool removeDuplicates)
{
List<string> lines = new List<string>();
for (int i = startLine; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(i);
lines.Add(document.GetText(line.Offset, line.Length));
}
lines.Sort(comparer);
if (removeDuplicates) {
lines = lines.Distinct(comparer).ToList();
}
using (document.OpenUndoGroup()) {
for (int i = 0; i < lines.Count; ++i) {
IDocumentLine line = document.GetLine(startLine + i);
document.Replace(line.Offset, line.Length, lines[i]);
}
// remove removed duplicate lines
for (int i = startLine + lines.Count; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(startLine + lines.Count);
document.Remove(line.Offset, line.TotalLength);
}
}
}
示例2: DocumentScript
public DocumentScript(IDocument document, CSharpFormattingOptions formattingOptions, TextEditorOptions options) : base(formattingOptions, options)
{
this.originalDocument = document.CreateDocumentSnapshot();
this.currentDocument = document;
Debug.Assert(currentDocument.Version.CompareAge(originalDocument.Version) == 0);
this.undoGroup = document.OpenUndoGroup();
}
示例3: SwapText
/// <summary>
/// Swaps 2 ranges of text in a document.
/// </summary>
static void SwapText(IDocument document, Location start1, Location end1, Location start2, Location end2)
{
if (start1 > start2) {
Location sw;
sw = start1; start1 = start2; start2 = sw;
sw = end1; end1 = end2; end2 = sw;
}
if (end1 >= start2)
throw new InvalidOperationException("Cannot swap overlaping segments");
int offset1 = document.PositionToOffset(start1);
int len1 = document.PositionToOffset(end1) - offset1;
int offset2 = document.PositionToOffset(start2);
int len2 = document.PositionToOffset(end2) - offset2;
string text1 = document.GetText(offset1, len1);
string text2 = document.GetText(offset2, len2);
using (var undoGroup = document.OpenUndoGroup()) {
document.Replace(offset2, len2, text1);
document.Replace(offset1, len1, text2);
}
}
示例4: ModifyDocument
public static void ModifyDocument(List<Modification> modifications, IDocument doc, int offset, int length, string newName)
{
using (doc.OpenUndoGroup()) {
foreach (Modification m in modifications) {
if (m.Document == doc) {
if (m.Offset < offset)
offset += m.LengthDifference;
}
}
int lengthDifference = newName.Length - length;
doc.Replace(offset, length, newName);
if (lengthDifference != 0) {
for (int i = 0; i < modifications.Count; ++i) {
Modification m = modifications[i];
if (m.Document == doc) {
if (m.Offset > offset) {
m.Offset += lengthDifference;
modifications[i] = m; // Modification is a value type
}
}
}
modifications.Add(new Modification(doc, offset, lengthDifference));
}
}
}
示例5: Apply
public void Apply(IDocument document)
{
using (document.OpenUndoGroup()) {
var changes = oldVersion.GetChangesTo(newVersion);
foreach (var change in changes)
document.Replace(change.Offset, change.RemovalLength, change.InsertedText);
}
}
示例6: Insert
public int Insert (IDocument document, string text)
{
int offset = document.GetOffset (Location);
using (var undo = document.OpenUndoGroup ()) {
text = DocumentUtilities.NormalizeNewLines(text, document, Location.Line);
var line = document.GetLineByOffset (offset);
int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset;
InsertNewLine (document, LineBefore, ref offset);
document.Insert (offset, text);
offset += text.Length;
InsertNewLine (document, LineAfter, ref offset);
return offset;
}
}