当前位置: 首页>>代码示例>>C#>>正文


C# ITextBuffer.Replace方法代码示例

本文整理汇总了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;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:13,代码来源:XmlDocCommentCompletionItem.cs

示例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;
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:49,代码来源:RoxygenBlock.cs

示例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);
        }
开发者ID:borota,项目名称:JTVS,代码行数:18,代码来源:JFormattingOptionsControl.cs

示例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);
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:19,代码来源:PythonFormattingOptionsControl.cs

示例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));
            }
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:20,代码来源:TextBufferUtility.cs

示例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());
 }
开发者ID:Gordon-Beeming,项目名称:WebEssentials2013,代码行数:6,代码来源:Base64DecodeSmartTag.cs

示例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());
 }
开发者ID:Russe11,项目名称:WebEssentials2013,代码行数:6,代码来源:Base64DecodeSmartTag.cs

示例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);
					}
				}
			}
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:61,代码来源:FirstUseOptimization.cs


注:本文中的ITextBuffer.Replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。