本文整理汇总了C#中ITextBuffer.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# ITextBuffer.Replace方法的具体用法?C# ITextBuffer.Replace怎么用?C# ITextBuffer.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextBuffer
的用法示例。
在下文中一共展示了ITextBuffer.Replace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertFirstHalf
private string InsertFirstHalf(ITextView textView, ITextBuffer subjectBuffer, char? commitChar, Span replacementSpan)
{
var insertedText = _beforeCaretText;
if (commitChar.HasValue && !char.IsWhiteSpace(commitChar.Value) && commitChar.Value != insertedText[insertedText.Length - 1])
{
// The caret goes after whatever commit character we spit.
insertedText += commitChar.Value;
}
subjectBuffer.Replace(replacementSpan, insertedText);
return insertedText;
}
示例2: TryInsertBlock
/// <summary>
/// Attempts to insert Roxygen documentation block based
/// on the user function signature.
/// </summary>
public static bool TryInsertBlock(ITextBuffer textBuffer, AstRoot ast, int position) {
// First determine if position is right before the function declaration
var snapshot = textBuffer.CurrentSnapshot;
ITextSnapshotLine line = null;
var lineNumber = snapshot.GetLineNumberFromPosition(position);
for (int i = lineNumber; i < snapshot.LineCount; i++) {
line = snapshot.GetLineFromLineNumber(i);
if (line.Length > 0) {
break;
}
}
if (line == null || line.Length == 0) {
return false;
}
Variable v;
int offset = line.Length - line.GetText().TrimStart().Length + 1;
if (line.Start + offset >= snapshot.Length) {
return false;
}
IFunctionDefinition fd = FunctionDefinitionExtensions.FindFunctionDefinition(textBuffer, ast, line.Start + offset, out v);
if (fd != null && v != null && !string.IsNullOrEmpty(v.Name)) {
int definitionStart = Math.Min(v.Start, fd.Start);
Span? insertionSpan = GetRoxygenBlockPosition(snapshot, definitionStart);
if (insertionSpan.HasValue) {
string lineBreak = snapshot.GetLineFromPosition(position).GetLineBreakText();
if (string.IsNullOrEmpty(lineBreak)) {
lineBreak = "\n";
}
string block = GenerateRoxygenBlock(v.Name, fd, lineBreak);
if (block.Length > 0) {
if (insertionSpan.Value.Length == 0) {
textBuffer.Insert(insertionSpan.Value.Start, block + lineBreak);
} else {
textBuffer.Replace(insertionSpan.Value, block);
}
return true;
}
}
}
return false;
}
示例3: JFormattingOptionsControl
public JFormattingOptionsControl()
{
InitializeComponent();
_optionsTree.AfterSelect += AfterSelectOrCheckNode;
_optionsTree.AfterCheck += AfterSelectOrCheckNode;
var editorFactory = JToolsPackage.ComponentModel.GetService<ITextEditorFactoryService>();
var bufferFactory = JToolsPackage.ComponentModel.GetService<ITextBufferFactoryService>();
var contentTypeRegistry = JToolsPackage.ComponentModel.GetService<IContentTypeRegistryService>();
var textContentType = contentTypeRegistry.GetContentType("J");
_buffer = bufferFactory.CreateTextBuffer(textContentType);
var editor = editorFactory.CreateTextView(_buffer);
_editorHost.Child = (UIElement)editor;
_buffer.Replace(new Span(0, 0), DefaultText);
}
示例4: PythonFormattingOptionsControl
public PythonFormattingOptionsControl(IServiceProvider serviceProvider) {
_serviceProvider = serviceProvider;
InitializeComponent();
_optionsTree.AfterSelect += AfterSelectOrCheckNode;
_optionsTree.AfterCheck += AfterSelectOrCheckNode;
var compModel = _serviceProvider.GetComponentModel();
var editorFactory = compModel.GetService<ITextEditorFactoryService>();
var bufferFactory = compModel.GetService<ITextBufferFactoryService>();
var contentTypeRegistry = compModel.GetService<IContentTypeRegistryService>();
var textContentType = contentTypeRegistry.GetContentType("Python");
_buffer = bufferFactory.CreateTextBuffer(textContentType);
var editor = editorFactory.CreateTextView(_buffer, CreateRoleSet());
_editorHost.Child = (UIElement)editor;
_buffer.Replace(new Span(0, 0), DefaultText);
}
示例5: ApplyTextChange
public static void ApplyTextChange(ITextBuffer textBuffer, int start, int oldLength, int newLength, string newText)
{
TextChange tc = new TextChange();
tc.OldRange = new TextRange(start, oldLength);
tc.NewRange = new TextRange(start, newLength);
tc.OldTextProvider = new TextProvider(textBuffer.CurrentSnapshot);
if (oldLength == 0 && newText.Length > 0)
{
textBuffer.Insert(start, newText);
}
else if (oldLength > 0 && newText.Length > 0)
{
textBuffer.Replace(new Span(start, oldLength), newText);
}
else
{
textBuffer.Delete(new Span(start, oldLength));
}
}
示例6: ReplaceUrlValue
private static void ReplaceUrlValue(string fileName, ITextBuffer buffer, AttributeNode src)
{
string relative = FileHelpers.RelativePath(buffer.GetFileName(), fileName);
Span span = new Span(src.ValueRangeUnquoted.Start, src.ValueRangeUnquoted.Length);
buffer.Replace(span, relative.ToLowerInvariant());
}
示例7: ReplaceUrlValue
private void ReplaceUrlValue(string fileName, ITextBuffer buffer, AttributeNode src)
{
string relative = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, fileName);
Span span = new Span(src.ValueRangeUnquoted.Start, src.ValueRangeUnquoted.Length);
buffer.Replace(span, relative.ToLowerInvariant());
}
示例8: InitializeAsync
async Task InitializeAsync(ITextBuffer buffer, string code, MetadataReference[] refs, string languageName, ISynchronousTagger<IClassificationTag> tagger, CompilationOptions compilationOptions, ParseOptions parseOptions) {
using (var workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices)) {
var documents = new List<DocumentInfo>();
var projectId = ProjectId.CreateNewId();
documents.Add(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "main.cs", null, SourceCodeKind.Regular, TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create())));
var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", Guid.NewGuid().ToString(), languageName,
compilationOptions: compilationOptions
.WithOptimizationLevel(OptimizationLevel.Release)
.WithPlatform(Platform.AnyCpu)
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default),
parseOptions: parseOptions,
documents: documents,
metadataReferences: refs,
isSubmission: false, hostObjectType: null);
workspace.AddProject(projectInfo);
foreach (var doc in documents)
workspace.OpenDocument(doc.Id);
buffer.Replace(new Span(0, buffer.CurrentSnapshot.Length), code);
{
// Initialize classification code paths
var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length));
foreach (var tagSpan in tagger.GetTags(spans, CancellationToken.None)) { }
}
{
// Initialize completion code paths
var info = CompletionInfo.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
var completionTrigger = CompletionTrigger.Default;
var completionList = await info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, 0, completionTrigger);
}
}
{
// Initialize signature help code paths
var info = SignatureHelpInfo.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
int sigHelpIndex = code.IndexOf("sighelp");
Debug.Assert(sigHelpIndex >= 0);
var triggerInfo = new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.InvokeSignatureHelpCommand);
var items = await info.Value.SignatureHelpService.GetItemsAsync(info.Value.Document, sigHelpIndex, triggerInfo);
}
}
{
// Initialize quick info code paths
var info = QuickInfoState.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
int quickInfoIndex = code.IndexOf("Equals");
Debug.Assert(quickInfoIndex >= 0);
var item = await info.Value.QuickInfoService.GetItemAsync(info.Value.Document, quickInfoIndex);
}
}
}
}