示例#1
0
            public void EndPoint()
            {
                var textBuffer = CreateTextBuffer("cat");
                var point      = new SnapshotCodePoint(textBuffer.GetEndPoint());

                Assert.False(point.IsCharacter('c'));
            }
示例#2
0
            public void AddPastEnd()
            {
                var textBuffer = CreateTextBuffer("A𠈓C");
                var point      = new SnapshotCodePoint(textBuffer.GetStartPoint());

                Assert.Throws <ArgumentOutOfRangeException>(() => point.Add(4));
            }
示例#3
0
            public void Simple()
            {
                var textBuffer = CreateTextBuffer("cat");
                var point      = new SnapshotCodePoint(textBuffer.GetStartPoint());

                Assert.True(point.IsCharacter('c'));
                Assert.False(point.IsCharacter('\t'));
            }
示例#4
0
            public void AddAcrossLines()
            {
                var textBuffer = CreateTextBuffer("cat", "dog");
                var point1     = new SnapshotCodePoint(textBuffer.GetStartPoint());
                var point2     = point1.Add(5);

                Assert.Equal(1, point2.Line.LineNumber);
            }
示例#5
0
            public void SubtractAcrossLines()
            {
                var textBuffer = CreateTextBuffer("cat", "dog");
                var point1     = new SnapshotCodePoint(textBuffer.GetPointInLine(line: 1, column: 0));
                var point2     = point1.Subtract(2);

                Assert.Equal(0, point2.Line.LineNumber);
            }
示例#6
0
            public void SubtractSimple()
            {
                var textBuffer = CreateTextBuffer("A𠈓C");
                var point      = new SnapshotCodePoint(textBuffer.GetEndPoint());

                AssertIt(point.Subtract(1), codePointInfo: CodePointInfo.SimpleCharacter, text: "C", position: 3);
                AssertIt(point.Subtract(2), codePointInfo: CodePointInfo.SurrogatePairHighCharacter, text: "𠈓", position: 1);
                AssertIt(point.Subtract(3), codePointInfo: CodePointInfo.SimpleCharacter, text: "A", position: 0);
            }
示例#7
0
            public void EndPoint()
            {
                var textBuffer = CreateTextBuffer("cat");
                var point      = new SnapshotCodePoint(textBuffer.GetEndPoint());

                Assert.Equal(textBuffer.GetEndPoint(), point.StartPoint);
                Assert.Equal(textBuffer.GetEndPoint(), point.EndPoint);
                Assert.True(point.IsEndPoint);
            }
示例#8
0
        /// <summary>
        /// Calculate the dimensions of the caret
        /// </summary>
        private Size CalculateCaretSize(out string caretCharacter)
        {
            caretCharacter = "";

            var defaultWidth = _formattedText.Width;
            var width        = defaultWidth;
            var height       = _textView.LineHeight;

            if (IsRealCaretVisible)
            {
                // Get the caret string and caret width.
                var line = TextViewLineContainingCaret;
                height = line.Height;
                var point         = _textView.Caret.Position.BufferPosition;
                var codePointInfo = new SnapshotCodePoint(point).CodePointInfo;
                if (point.Position < point.Snapshot.Length)
                {
                    var pointCharacter = point.GetChar();
                    if (_controlCharUtil.TryGetDisplayText(pointCharacter, out string caretString))
                    {
                        // Handle control character notation.
                        caretCharacter = caretString;
                        width          = line.GetCharacterBounds(point).Width;
                    }
                    else if (codePointInfo == CodePointInfo.SurrogatePairHighCharacter)
                    {
                        // Handle surrogate pairs.
                        caretCharacter = new SnapshotSpan(point, 2).GetText();
                        width          = line.GetCharacterBounds(point).Width;
                    }
                    else if (pointCharacter == '\t')
                    {
                        // Handle tab as no character and default width,
                        // except no wider than the tab's screen width.
                        caretCharacter = "";
                        width          = Math.Min(defaultWidth, line.GetCharacterBounds(point).Width);
                    }
                    else if (pointCharacter == '\r' || pointCharacter == '\n')
                    {
                        // Handle linebreak.
                        caretCharacter = "";
                        width          = line.GetCharacterBounds(point).Width;
                    }
                    else
                    {
                        // Handle ordinary UTF16 character.
                        caretCharacter = pointCharacter.ToString();
                        width          = line.GetCharacterBounds(point).Width;
                    }
                }
            }

            return(new Size(width, height));
        }
示例#9
0
            public void SubtractKeepsLineReference()
            {
                var textBuffer = CreateTextBuffer("cat", "dog");
                var point      = new SnapshotCodePoint(textBuffer.GetStartPoint().GetContainingLine(), 4);
                var line       = point.Line;

                while (point.StartPosition > 0)
                {
                    point = point.Subtract(1);
                    Assert.Same(line, point.Line);
                }
            }
示例#10
0
            public void AddKeepsLineReference()
            {
                var textBuffer = CreateTextBuffer("cat", "dog");
                var point      = new SnapshotCodePoint(textBuffer.GetStartPoint());
                var line       = point.Line;

                for (int i = 0; i < 3; i++)
                {
                    point = point.Add(1);
                    Assert.Same(line, point.Line);
                }
            }
示例#11
0
        private static void AssertIt(SnapshotCodePoint point, int?codePoint = null, CodePointInfo codePointInfo = null, string text = null, int?position = null)
        {
            if (codePoint.HasValue)
            {
                Assert.Equal(codePoint.Value, point.CodePoint);
            }

            if (codePointInfo != null)
            {
                Assert.Equal(codePointInfo, point.CodePointInfo);
            }

            if (text != null)
            {
                Assert.Equal(text, point.GetText());
            }

            if (position != null)
            {
                Assert.Equal(position.Value, point.StartPoint.Position);
            }
        }
示例#12
0
        /// <summary>
        /// Calculate the dimensions of the caret
        /// </summary>
        private Size CalculateCaretSize(VirtualSnapshotPoint caretPoint, out string caretCharacter)
        {
            caretCharacter = "";

            var defaultWidth = _formattedText.Width;
            var width        = defaultWidth;
            var height       = _textView.LineHeight;

            if (IsRealCaretVisible(caretPoint, out var textViewLine))
            {
                // Get the caret height.
                height = textViewLine.TextHeight;

                // Try to use the same line height that a selection would use.
                var textViewLines = _textView.TextViewLines;
                if (textViewLines != null && textViewLines.IsValid)
                {
                    var geometry = textViewLines.GetMarkerGeometry(textViewLine.Extent);
                    if (geometry != null)
                    {
                        height = geometry.Bounds.Height;
                    }
                }

                // Get the caret string and caret width.
                var point         = caretPoint.Position;
                var codePointInfo = new SnapshotCodePoint(point).CodePointInfo;
                if (point.Position < point.Snapshot.Length)
                {
                    var pointCharacter = point.GetChar();
                    if (_controlCharUtil.TryGetDisplayText(pointCharacter, out string caretString))
                    {
                        // Handle control character notation.
                        caretCharacter = caretString;
                        width          = textViewLine.GetCharacterBounds(point).Width;
                    }
                    else if (codePointInfo == CodePointInfo.SurrogatePairHighCharacter)
                    {
                        // Handle surrogate pairs.
                        caretCharacter = new SnapshotSpan(point, 2).GetText();
                        width          = textViewLine.GetCharacterBounds(point).Width;
                    }
                    else if (pointCharacter == '\t')
                    {
                        // Handle tab as no character and default width,
                        // except no wider than the tab's screen width.
                        caretCharacter = "";
                        width          = Math.Min(defaultWidth, textViewLine.GetCharacterBounds(point).Width);
                    }
                    else if (pointCharacter == '\r' || pointCharacter == '\n')
                    {
                        // Handle linebreak.
                        caretCharacter = "";
                        width          = textViewLine.GetCharacterBounds(point).Width;
                    }
                    else
                    {
                        // Handle ordinary UTF16 character.
                        caretCharacter = pointCharacter.ToString();
                        width          = textViewLine.GetCharacterBounds(point).Width;
                    }
                }
            }

            return(new Size(width, height));
        }