AddTracking() публичный Метод

Add tracking for text in span for document with id docCookie.
public AddTracking ( IWpfTextView wpfTextView, ITextSnapshot textSnapshot, long docCookie, Span span ) : void
wpfTextView IWpfTextView
textSnapshot ITextSnapshot
docCookie long
span Span
Результат void
        /// <summary>
        /// Highlight the source code on a particular line
        /// </summary>
        private static void AttachMarkerToTextView(IWpfTextView textView, long docCookie, ResultTextMarker marker,
                                                   int line, int column, int endLine, int endColumn)
        {
            // If for some reason the start line is not correct, just skip the highlighting
            ITextSnapshot textSnapshot = textView.TextSnapshot;

            if (line > textSnapshot.LineCount)
            {
                return;
            }

            Span spanToColor;
            int  markerStart, markerEnd = 0;

            try
            {
                // Fix up the end line number if it's inconsistent
                if (endLine <= 0 || endLine < line)
                {
                    endLine = line;
                }

                bool coerced = false;

                // Calculate the start and end marker bound. Adjust for the column values if
                // the values don't make sense. Make sure we handle the case of empty file correctly
                ITextSnapshotLine startTextLine = textSnapshot.GetLineFromLineNumber(Math.Max(line - 1, 0));
                ITextSnapshotLine endTextLine   = textSnapshot.GetLineFromLineNumber(Math.Max(endLine - 1, 0));
                if (column <= 0 || column >= startTextLine.Length)
                {
                    column  = 1;
                    coerced = true;
                }

                // Calculate the end marker bound. Perform coersion on the values if they aren't consistent
                if (endColumn <= 0 && endColumn >= endTextLine.Length)
                {
                    endColumn = endTextLine.Length;
                    coerced   = true;
                }

                // If we are highlighting just one line and the column values don't make
                // sense or we corrected one or more of them, then simply mark the
                // entire line
                if (endLine == line && (coerced || column >= endColumn))
                {
                    column    = 1;
                    endColumn = endTextLine.Length;
                }

                // Create a span with the calculated markers
                markerStart = startTextLine.Start.Position + column - 1;
                markerEnd   = endTextLine.Start.Position + endColumn;
                spanToColor = Span.FromBounds(markerStart, markerEnd);

                marker.AddTracking(textView, textSnapshot, docCookie, spanToColor);
            }
            catch (Exception e)
            {
                // Log the exception and move ahead. We don't want to bubble this or fail.
                // We just don't color the problem line.
                Debug.Print(e.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Highlight the source code on a particular line
        /// </summary>
        private static void AttachMarkerToTextView(IWpfTextView textView, long docCookie, ResultTextMarker marker,
            int line, int column, int endLine, int endColumn)
        {
            // If for some reason the start line is not correct, just skip the highlighting
            ITextSnapshot textSnapshot = textView.TextSnapshot;
            if (line > textSnapshot.LineCount)
            {
                return;
            }

            Span spanToColor;
            int markerStart, markerEnd = 0;

            try
            {
                // Fix up the end line number if it's inconsistent
                if (endLine <= 0 || endLine < line)
                {
                    endLine = line;
                }

                bool coerced = false;

                // Calculate the start and end marker bound. Adjust for the column values if
                // the values don't make sense. Make sure we handle the case of empty file correctly
                ITextSnapshotLine startTextLine = textSnapshot.GetLineFromLineNumber(Math.Max(line - 1, 0));
                ITextSnapshotLine endTextLine = textSnapshot.GetLineFromLineNumber(Math.Max(endLine - 1, 0));
                if (column <= 0 || column >= startTextLine.Length)
                {
                    column = 1;
                    coerced = true;
                }

                // Calculate the end marker bound. Perform coersion on the values if they aren't consistent
                if (endColumn <= 0 && endColumn >= endTextLine.Length)
                {
                    endColumn = endTextLine.Length;
                    coerced = true;
                }

                // If we are highlighting just one line and the column values don't make
                // sense or we corrected one or more of them, then simply mark the
                // entire line
                if (endLine == line && (coerced || column >= endColumn))
                {
                    column = 1;
                    endColumn = endTextLine.Length;
                }

                // Create a span with the calculated markers
                markerStart = startTextLine.Start.Position + column - 1;
                markerEnd = endTextLine.Start.Position + endColumn;
                spanToColor = Span.FromBounds(markerStart, markerEnd);

                marker.AddTracking(textView, textSnapshot, docCookie, spanToColor);
            }
            catch (Exception e)
            {
                // Log the exception and move ahead. We don't want to bubble this or fail.
                // We just don't color the problem line.
                Debug.Print(e.Message);
            }
        }