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


C# ITextBuffer.Insert方法代码示例

本文整理汇总了C#中ITextBuffer.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# ITextBuffer.Insert方法的具体用法?C# ITextBuffer.Insert怎么用?C# ITextBuffer.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextBuffer的用法示例。


在下文中一共展示了ITextBuffer.Insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClassifier

        private IClassifier GetClassifier(string content, out ITextBuffer textBuffer) {
            textBuffer = _tbfs.CreateTextBuffer(new ContentTypeMock(MdContentTypeDefinition.ContentType));
            textBuffer.Insert(0, content);

            MdClassifierProvider classifierProvider = new MdClassifierProvider(_crs, _ctrs, _cnp, _exportProvider.GetExportedValue<ICoreShell>());
           return classifierProvider.GetClassifier(textBuffer);
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:7,代码来源:MarkdownCodeTest.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: 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

示例4: IndentLines

        /// <summary>
        /// Appends indentation to each line so formatted text appears properly 
        /// indented inside the host document (script block in HTML page).
        /// </summary>
        private static void IndentLines(ITextView textView, ITextBuffer textBuffer,
                                        ITextRange range, AstRoot ast,
                                        RFormatOptions options, int originalIndentSizeInSpaces) {
            ITextSnapshot snapshot = textBuffer.CurrentSnapshot;
            ITextSnapshotLine firstLine = snapshot.GetLineFromPosition(range.Start);
            ITextSnapshotLine lastLine = snapshot.GetLineFromPosition(range.End);

            IREditorDocument document = REditorDocument.TryFromTextBuffer(textBuffer);

            for (int i = firstLine.LineNumber; i <= lastLine.LineNumber; i++) {
                // Snapshot is updated after each insertion so do not cache
                ITextSnapshotLine line = textBuffer.CurrentSnapshot.GetLineFromLineNumber(i);
                int indent = SmartIndenter.GetSmartIndent(line, ast, originalIndentSizeInSpaces, formatting: true);
                if (indent > 0 && line.Length > 0 && line.Start >= range.Start) {
                    // Check current indentation and correct for the difference
                    int currentIndentSize = IndentBuilder.TextIndentInSpaces(line.GetText(), options.TabSize);
                    indent = Math.Max(0, indent - currentIndentSize);
                    if (indent > 0) {
                        string indentString = IndentBuilder.GetIndentString(indent, options.IndentType, options.TabSize);
                        textBuffer.Insert(line.Start, indentString);
                        if (document == null) {
                            // Typically this is a test scenario only. In the real editor
                            // instance document is available and automatically updates AST
                            // when whitespace inserted, not no manual update is necessary.
                            ast.ReflectTextChange(line.Start, 0, indentString.Length, new TextProvider(textBuffer.CurrentSnapshot));
                        }
                    }
                }
            }
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:34,代码来源:RangeFormatter.cs

示例5: InsertSecondHalf

 private void InsertSecondHalf(ITextView textView, ITextBuffer subjectBuffer, string insertedText, Span replacementSpan)
 {
     subjectBuffer.Insert(replacementSpan.Start + insertedText.Length, _afterCaretText);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:4,代码来源:XmlDocCommentCompletionItem.cs

示例6: AddImport

        public static void AddImport(
            IServiceProvider serviceProvider,
            ITextBuffer buffer,
            ITextView view,
            string fromModule,
            string name
        ) {
            var analyzer = buffer.GetAnalyzer(serviceProvider);
            var curAst = analyzer.ParseSnapshot(buffer.CurrentSnapshot);

            var suiteBody = curAst.Body as SuiteStatement;
            Statement insertBefore = null;
            if (suiteBody != null) {
                bool firstStatement = true;

                foreach (var statement in suiteBody.Statements) {
                    if (firstStatement && IsDocString(statement as ExpressionStatement)) {
                        // doc string, ignore this
                        firstStatement = false;
                        continue;
                    }

                    firstStatement = false;

                    // __future__ imports go first
                    if (fromModule == null || fromModule != "__future__") {
                        if (statement is ImportStatement) {
                            // we insert after this
                            continue;
                        } else if (statement is FromImportStatement) {
                            // we might update this, we might insert after
                            FromImportStatement fromImport = statement as FromImportStatement;
                            if (fromImport.Root.MakeString() == fromModule) {
                                // update the existing from ... import statement to include the new name.
                                UpdateFromImport(curAst, buffer, fromImport, name);
                                return;
                            }
                            continue;
                        }
                    }

                    // this isn't an import, we insert before this statement
                    insertBefore = statement;
                    break;
                }
            }

            int start;
            if (insertBefore != null) {
                var location = insertBefore.GetStart(curAst);

                var point = buffer.CurrentSnapshot.GetLineFromLineNumber(location.Line - 1).Start;
                // the span starts after any whitespace, so walk backup and see if we should skip some lines
                if (point.Position != 0) {
                    var prevPoint = point.Subtract(1);

                    //  walk past all the previous lines
                    var classifier = buffer.GetPythonClassifier();

                    bool moved = false;
                    while (prevPoint.Position != 0 &&
                        (char.IsWhiteSpace(prevPoint.GetChar()) || IsCommentChar(prevPoint, classifier))) {
                        prevPoint = prevPoint.Subtract(1);
                        moved = true;
                    }
                    prevPoint = prevPoint.Add(1);

                    // then walk forward one line
                    if (moved) {
                        int lineNum = prevPoint.GetContainingLine().LineNumber;
                        do {
                            prevPoint = prevPoint.Add(1);
                        } while (lineNum == prevPoint.GetContainingLine().LineNumber);
                    }

                    point = prevPoint;
                }
                start = point.Position;
            } else {
                start = 0;
            }

            buffer.Insert(start, MakeImportCode(fromModule, name) + view.Options.GetNewLineCharacter());
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:84,代码来源:MissingImportAnalysis.cs

示例7: Type

 public static void Type(ITextBuffer textBuffer, int start, string textToType) {
     for (int i = 0; i < textToType.Length; i++) {
         textBuffer.Insert(start + i, textToType[i].ToString());
     }
 }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:5,代码来源:Typing.cs


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