本文整理汇总了C#中ITextUndoHistoryRegistry.RegisterHistory方法的典型用法代码示例。如果您正苦于以下问题:C# ITextUndoHistoryRegistry.RegisterHistory方法的具体用法?C# ITextUndoHistoryRegistry.RegisterHistory怎么用?C# ITextUndoHistoryRegistry.RegisterHistory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextUndoHistoryRegistry
的用法示例。
在下文中一共展示了ITextUndoHistoryRegistry.RegisterHistory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextBufferUndoManager
public TextBufferUndoManager(ITextBuffer textBuffer, ITextUndoHistoryRegistry textUndoHistoryRegistry) {
if (textBuffer == null)
throw new ArgumentNullException(nameof(textBuffer));
if (textUndoHistoryRegistry == null)
throw new ArgumentNullException(nameof(textUndoHistoryRegistry));
changes = new List<ChangeInfo>();
TextBuffer = textBuffer;
this.textUndoHistoryRegistry = textUndoHistoryRegistry;
textBufferUndoHistory = textUndoHistoryRegistry.RegisterHistory(TextBuffer);
TextBuffer.Changed += TextBuffer_Changed;
TextBuffer.PostChanged += TextBuffer_PostChanged;
}
示例2: Execute
public void Execute(ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry)
{
var isReversed = textView.Selection.IsReversed;
var newSelection = new List<Tuple<int, int>>();
var undoHistory = textUndoHistoryRegistry.RegisterHistory(textView);
using (var transaction = undoHistory.CreateTransaction("Comment Selection"))
{
foreach (var span in textView.Selection.SelectedSpans)
{
var startLine = span.Start.GetContainingLine().LineNumber;
var endLine = span.End.GetContainingLine().LineNumber;
if (startLine > endLine)
{
var tmp = startLine;
startLine = endLine;
endLine = tmp;
}
var edit = span.Snapshot.TextBuffer.CreateEdit();
for (int lineNumber = startLine; lineNumber <= endLine; ++lineNumber)
{
var line = span.Snapshot.GetLineFromLineNumber(lineNumber);
Modify(edit, line);
}
edit.Apply();
newSelection.Add(Tuple.Create(startLine, endLine));
}
transaction.Complete();
}
textView.Selection.Select(new NormalizedSnapshotSpanCollection(
newSelection.Select(l => new SnapshotSpan(
textView.TextSnapshot.GetLineFromLineNumber(l.Item1).Start,
textView.TextSnapshot.GetLineFromLineNumber(l.Item2).End)
)
)[0], isReversed);
}
示例3: Execute
public void Execute(ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry)
{
var undoHistory = textUndoHistoryRegistry.RegisterHistory(textView);
using (var transaction = undoHistory.CreateTransaction("Format Document"))
{
var text = textView.TextBuffer.CurrentSnapshot.GetText();
var formatted = new StringWriter();
var parser = new Parser(new Scanner(new StringReader(text), skipComments: false));
var emitter = new Emitter(formatted);
while (parser.MoveNext())
{
emitter.Emit(parser.Current);
}
var edit = textView.TextBuffer.CreateEdit();
edit.Replace(0, text.Length, formatted.ToString());
edit.Apply();
transaction.Complete();
}
}