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


C# ITextSnapshotLine类代码示例

本文整理汇总了C#中ITextSnapshotLine的典型用法代码示例。如果您正苦于以下问题:C# ITextSnapshotLine类的具体用法?C# ITextSnapshotLine怎么用?C# ITextSnapshotLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: foreach

 int? ISmartIndent.GetDesiredIndentation(ITextSnapshotLine line)
 {
     var snap = _textView.TextSnapshot;
     // get all of the previous lines
     var lines = snap.Lines.Reverse().Skip(snap.LineCount - line.LineNumber);
     foreach (ITextSnapshotLine prevLine in lines)
     {
         var text = prevLine.GetText();
         if (text.All(c2 => System.Char.IsWhiteSpace(c2)))
         {
             continue;
         }
         var toks = Utils.LexString(text).ToList();
         if (toks.Last().Type == RustLexer.RustLexer.LBRACE)
         {
             return prevLine.GetText().TakeWhile(c2 => c2 == ' ').Count() + 4;
         }
         else if (toks.Any(tok => tok.Type == RustLexer.RustLexer.RBRACE))
         {
             ed.MoveLineUp(false);
             ed.DecreaseLineIndent();
             ed.MoveLineDown(false);
             return prevLine.GetText().TakeWhile(c2 => c2 == ' ').Count();
         }
     }
     // otherwise, there are no lines ending in braces before us.
     return null;
 }
开发者ID:rwray,项目名称:VisualRust,代码行数:28,代码来源:VisualRustSmartIndent.cs

示例2: OvLine

        //to be modified

        //constructor
        public OvLine(Canvas canvas, ITextSnapshotLine itv, float bzCurvArea, OvCollection parent)
        {
            _bzCurvArea = bzCurvArea;

            lnNumber = itv.LineNumber;
            lnStart = 0.0f;
            lnTextStart = (float)Find1stChar(itv);
            //if (lnNumber == 65) System.Diagnostics.Trace.WriteLine("%%%                 REGEX: " + lnTextStart ); 
            lnEnd = (float)itv.Length;
            lnHeight = 1.0f;
            lnLength = itv.Length;
            lnColor = new System.Windows.Media.Color();                    //get the color of the textview
            lnFocus = false;

            myCanvas = canvas;
            myPath = new Path();
            myParent = parent;

            IsSeleted = false;
            

            this.myPath.MouseEnter += new System.Windows.Input.MouseEventHandler(myPath_MouseEnter);
            this.myPath.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(myPath_MouseLeftButtonDown);
            this.myPath.MouseLeave += new System.Windows.Input.MouseEventHandler(myPath_MouseLeave);

            
        }
开发者ID:mintberry,项目名称:stackrecaller,代码行数:30,代码来源:OvLine.cs

示例3: PerformMove

        public int PerformMove(IWpfTextView view, ITextSnapshotLine lineToSwap, int insertPosition)
        {
            var insertedText = lineToSwap.GetTextIncludingLineBreak();

            if(insertPosition == view.TextSnapshot.Length)
            {
                // We don't want ot move the line break if the insert position is the last character of the
                // document but also the first character of the line (i.e. an empty line at the end of the document)
                var lineUnderInsertPosition = view.TextSnapshot.GetLineFromPosition(insertPosition);
                if (lineUnderInsertPosition.Length > 0)
                {
                    // Move the line break to the start of the text to insert
                    insertedText = (Environment.NewLine + insertedText).Substring(0, insertedText.Length);
                }
            }

            using (var edit = view.TextBuffer.CreateEdit())
            {
                edit.Delete(lineToSwap.Start, lineToSwap.LengthIncludingLineBreak);
                edit.Insert(insertPosition, insertedText);
                edit.Apply();
            }

            return -lineToSwap.LengthIncludingLineBreak;
        }
开发者ID:aenmeyk,项目名称:MoveLine,代码行数:25,代码来源:LineMoverUp.cs

示例4: GetIndentationOfLine

            protected IndentationResult GetIndentationOfLine(ITextSnapshotLine lineToMatch, int addedSpaces)
            {
                var firstNonWhitespace = lineToMatch.GetFirstNonWhitespacePosition();
                firstNonWhitespace = firstNonWhitespace ?? lineToMatch.End.Position;

                return GetIndentationOfPosition(new SnapshotPoint(lineToMatch.Snapshot, firstNonWhitespace.Value), addedSpaces);
            }
开发者ID:nemec,项目名称:roslyn,代码行数:7,代码来源:AbstractIndentationService.AbstractIndenter.cs

示例5: GetDesiredIndentation

        public int? GetDesiredIndentation(ITextSnapshotLine line)
        {
            // get point at the subject buffer
            var mappingPoint = _view.BufferGraph.CreateMappingPoint(line.Start, PointTrackingMode.Negative);

            // TODO (https://github.com/dotnet/roslyn/issues/5281): Remove try-catch.
            SnapshotPoint? point = null;
            try
            {
                point = mappingPoint.GetInsertionPoint(b => b.ContentType.IsOfType(_contentType.TypeName));
            }
            catch (ArgumentOutOfRangeException)
            {
                // Suppress this to work around DevDiv #144964.
                // Note: Other callers might be affected, but this is the narrowest workaround for the observed problems.
                // A fix is already being reviewed, so a broader change is not required.
                return null;
            }

            if (!point.HasValue)
            {
                return null;
            }

            // Currently, interactive smart indenter returns indentation based
            // solely on subject buffer's information and doesn't consider spaces
            // in interactive window itself. Note: This means the ITextBuffer passed
            // to ISmartIndent.GetDesiredIndentation is not this.view.TextBuffer.
            return _indenter.GetDesiredIndentation(point.Value.GetContainingLine());
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:30,代码来源:InteractiveSmartIndenter.cs

示例6: GetDesiredIndentationAsync

        private async Task<int?> GetDesiredIndentationAsync(ITextSnapshotLine lineToBeIndented, CancellationToken cancellationToken)
        {
            if (lineToBeIndented == null)
            {
                throw new ArgumentNullException(@"line");
            }

            using (Logger.LogBlock(FunctionId.SmartIndentation_Start, cancellationToken))
            {
                var document = lineToBeIndented.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
                if (document == null)
                {
                    return null;
                }

                var service = document.GetLanguageService<IIndentationService>();
                if (service == null)
                {
                    return null;
                }

                var result = await service.GetDesiredIndentationAsync(document, lineToBeIndented.LineNumber, cancellationToken).ConfigureAwait(false);
                if (result == null)
                {
                    return null;
                }

                return result.Value.GetIndentation(_textView, lineToBeIndented);
            }
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:30,代码来源:SmartIndent.cs

示例7: GetDesiredIndentation

        public virtual int? GetDesiredIndentation(ITextSnapshotLine line)
        {
            try
            {
                vsIndentStyle indentStyle = IndentStyle;
                if (indentStyle == vsIndentStyle.vsIndentStyleNone)
                    return 0;

                int? result = null;

                if (indentStyle == vsIndentStyle.vsIndentStyleSmart)
                    result = GetSmartIndentation(line);

                if (result == null)
                    result = GetFallbackIndentation(line);

                return result;
            }
            catch (Exception ex)
            {
                // Throwing an exception from here will crash the IDE.
                if (ErrorHandler.IsCriticalException(ex))
                    throw;

                return null;
            }
        }
开发者ID:chandramouleswaran,项目名称:LangSvcV2,代码行数:27,代码来源:SmartIndent.cs

示例8: Modify

		protected override void Modify(ITextEdit edit, ITextSnapshotLine line)
		{
			if (line.GetText().StartsWith("#"))
			{
				edit.Delete(line.Start, 1);
			}
		}
开发者ID:modulexcite,项目名称:YamlDotNet.Editor,代码行数:7,代码来源:UncommentSelectionCommandHandler.cs

示例9: GetDesiredIndentation

		/// <summary>
		/// Gets the desired indentation
		/// </summary>
		/// <param name="textView">Text view</param>
		/// <param name="smartIndentationService">Smart indentation service</param>
		/// <param name="line">Line</param>
		/// <returns></returns>
		public static int? GetDesiredIndentation(ITextView textView, ISmartIndentationService smartIndentationService, ITextSnapshotLine line) {
			if (textView == null)
				throw new ArgumentNullException(nameof(textView));
			if (smartIndentationService == null)
				throw new ArgumentNullException(nameof(smartIndentationService));
			if (line == null)
				throw new ArgumentNullException(nameof(line));

			var indentStyle = textView.Options.GetIndentStyle();
			switch (indentStyle) {
			case IndentStyle.None:
				return 0;

			case IndentStyle.Block:
				return GetDesiredBlockIndentation(textView, line);

			case IndentStyle.Smart:
				var indentSize = smartIndentationService.GetDesiredIndentation(textView, line);
				Debug.Assert(indentSize == null || indentSize.Value >= 0);
				return indentSize;

			default:
				Debug.Fail($"Invalid {nameof(IndentStyle)}: {indentStyle}");
				return null;
			}
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:33,代码来源:IndentHelper.cs

示例10: GetDesiredIndentation

        private int? GetDesiredIndentation(ITextSnapshotLine lineToBeIndented, CancellationToken cancellationToken)
        {
            if (lineToBeIndented == null)
            {
                throw new ArgumentNullException(@"line");
            }

            using (Logger.LogBlock(FunctionId.SmartIndentation_Start, cancellationToken))
            {
                var document = lineToBeIndented.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
                var syncService = document?.GetLanguageService<ISynchronousIndentationService>();

                if (syncService != null)
                {
                    var result = syncService.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken);
                    return result?.GetIndentation(_textView, lineToBeIndented);
                }

                var asyncService = document?.GetLanguageService<IIndentationService>();
                if (asyncService != null)
                {
                    var result = asyncService.GetDesiredIndentation(document, lineToBeIndented.LineBreakLength, cancellationToken).WaitAndGetResult(cancellationToken);
                    return result?.GetIndentation(_textView, lineToBeIndented);
                }

                return null;
            }
        }
开发者ID:,项目名称:,代码行数:28,代码来源:

示例11: CheckLine

 public IEnumerable<TextLineCheckerError> CheckLine(ITextSnapshotLine line)
 {
     if (_chromiumSourceFiles.ApplyCodingStyle(_fileSystem, line)) {
     int indent = 0;
     var fragment = line.GetFragment(line.Start, line.End, TextLineFragment.Options.Default);
     foreach (var point in fragment.GetPoints()) {
       if (WhitespaceCharacters.IndexOf(point.GetChar()) >= 0) {
     // continue as long as we find whitespaces
     indent++;
       } else if (GetMarker(line, fragment, point) != null) {
     if (indent % 2 == 0) // even indentation is not ok
     {
       var marker = GetMarker(line, fragment, point);
       yield return new TextLineCheckerError {
         Span = new SnapshotSpan(point, marker.Length),
         Message =
           string.Format("Accessor \"{0}\" should always be indented 1 character less than rest of class body.",
                         marker)
       };
     }
       } else {
     // Stop at the first non-whitespace character.
     yield break;
       }
     }
       }
 }
开发者ID:nick-chromium,项目名称:vs-chromium,代码行数:27,代码来源:AccessorIndentChecker.cs

示例12: GetDesiredIndentation

        public int? GetDesiredIndentation(ITextSnapshotLine line)
        {
            // If we're on the first line, we can't really do anything clever.
            if (line.LineNumber == 0)
                return 0;

            var snapshot = line.Snapshot;

            // Walk up previous lines trying to find the first non-blank one.
            var previousNonBlankLine = snapshot.GetLineFromLineNumber(line.LineNumber - 1);
            while (previousNonBlankLine.LineNumber >= 1 && previousNonBlankLine.GetText().Trim().Length == 0)
                previousNonBlankLine = snapshot.GetLineFromLineNumber(previousNonBlankLine.LineNumber - 1);

            // If we didn't find an actual non-blank line, we can't really do anything clever.
            if (previousNonBlankLine.GetText().Trim() == "")
                return 0;

            var previousLineText = previousNonBlankLine.GetText();
            var previousLineIndent = previousLineText.Replace("\t", new string(' ', tabSize)).TakeWhile(char.IsWhiteSpace).Count();

            // If we started a block on the previous line; then add indent.
            if (previousLineText.TrimEnd().EndsWith("{"))
                return previousLineIndent + tabSize;
            else
                return previousLineIndent;
        }
开发者ID:modulexcite,项目名称:DartVS,代码行数:26,代码来源:SmartIndentProvider.cs

示例13: GetDesiredIndentation

 public int? GetDesiredIndentation(ITextSnapshotLine line)
 {
     if (JToolsPackage.Instance.LangPrefs.IndentMode == vsIndentStyle.vsIndentStyleSmart) {
         return AutoIndent.GetLineIndentation(line, _textView);
     } else {
         return null;
     }
 }
开发者ID:borota,项目名称:JTVS,代码行数:8,代码来源:SmartIndentProvider.cs

示例14: DoSmartIndent

 private int? DoSmartIndent(ITextSnapshotLine line)
 {
     var syntaxTree = line.Snapshot.GetSyntaxTree(CancellationToken.None);
     var root = syntaxTree.Root;
     var lineStartPosition = line.Start.Position;
     var indent = FindTotalParentChainIndent(root, lineStartPosition, 0);
     return indent;
 }
开发者ID:tgjones,项目名称:HlslTools,代码行数:8,代码来源:SmartIndent.cs

示例15: GetLineIndentation

        internal static int? GetLineIndentation(ITextSnapshotLine line, ITextView textView)
        {
            var options = textView.Options;

            ITextSnapshotLine baseline;
            string baselineText;
            SkipPreceedingBlankLines(line, out baselineText, out baseline);

            ITextBuffer targetBuffer = textView.TextBuffer;
            if (!targetBuffer.ContentType.IsOfType(JCoreConstants.ContentType)) {
                var match = textView.BufferGraph.MapDownToFirstMatch(line.Start, PointTrackingMode.Positive, JContentTypePrediciate, PositionAffinity.Successor);
                if (match == null) {
                    return 0;
                }
                targetBuffer = match.Value.Snapshot.TextBuffer;
            }

            var classifier = targetBuffer.GetJClassifier();
            if (classifier == null) {
                // workaround debugger canvas bug - they wire our auto-indent provider up to a C# buffer
                // (they query MEF for extensions by hand and filter incorrectly) and we don't have a J classifier.
                // So now the user's auto-indent is broken in C# but returning null is better than crashing.
                return null;
            }

            var desiredIndentation = CalculateIndentation(baselineText, baseline, options, classifier, textView);

            var caretLine = textView.Caret.Position.BufferPosition.GetContainingLine();
            // VS will get the white space when the user is moving the cursor or when the user is doing an edit which
            // introduces a new line.  When the user is moving the cursor the caret line differs from the line
            // we're querying.  When editing the lines are the same and so we want to account for the white space of
            // non-blank lines.  An alternate strategy here would be to watch for the edit and fix things up after
            // the fact which is what would happen pre-Dev10 when the language would not get queried for non-blank lines
            // (and is therefore what C# and other languages are doing).
            if (caretLine.LineNumber == line.LineNumber) {
                var lineText = caretLine.GetText();
                int indentationUpdate = 0;
                for (int i = textView.Caret.Position.BufferPosition.Position - caretLine.Start; i < lineText.Length; i++) {
                    if (lineText[i] == ' ') {
                        indentationUpdate++;
                    } else if (lineText[i] == '\t') {
                        indentationUpdate += textView.Options.GetIndentSize();
                    } else {
                        if (indentationUpdate > desiredIndentation) {
                            // we would dedent this line (e.g. there's a return on the previous line) but the user is
                            // hitting enter with a statement to the right of the caret and they're in the middle of white space.
                            // So we need to instead just maintain the existing indentation level.
                            desiredIndentation = Math.Max(GetIndentation(baselineText, options.GetTabSize()) - indentationUpdate, 0);
                        } else {
                            desiredIndentation -= indentationUpdate;
                        }
                        break;
                    }
                }
            }

            return desiredIndentation;
        }
开发者ID:borota,项目名称:JTVS,代码行数:58,代码来源:AutoIndent.cs


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