Exemplo n.º 1
0
        internal void EnsureCursorVisible(int column, int line)
        {
            if (this.MaxVisibleLines <= 0)
            {
                return; // Not ready to do so yet.
            }
            int vertPageSize   = this.MaxVisibleLines;
            int currentTopLine = (int)Math.Floor(VerticalOffset / Configurations.FontDisplayHeight);

            int newTopLine = currentTopLine;

            if (line < currentTopLine)
            {
                newTopLine = line;
            }
            else if (line >= (currentTopLine + vertPageSize))
            {
                newTopLine = line - vertPageSize + 1;
            }
            else if (contentExtent.Height <= viewportSize.Height)
            {
                newTopLine = 0;
            }

            if (newTopLine != currentTopLine)
            {
                SetVerticalOffset(newTopLine * Configurations.FontDisplayHeight);
            }

            int horzPageSize      = GetMaxVisibleColumns(viewportSize.Width);
            int currentLeftColumn = (int)Math.Floor(HorizontalOffset / Configurations.FormatFontWidth);

            // What is visible is "visual", does not mean the actual character offset.
            // For a meaningful comparison, we need to convert from "actual offset" to
            // "visual offset" before comparing it with "currentLeftColumn" (visual).
            //
            CharPosition converter    = Solution.Current.ActiveScript.CreateCharPosition();
            int          visualColumn = converter.CharToVisualOffset(line, column);

            int newLeftColumn = currentLeftColumn;

            if (visualColumn < currentLeftColumn)
            {
                newLeftColumn = visualColumn;
            }
            else if (visualColumn >= (currentLeftColumn + horzPageSize))
            {
                newLeftColumn = visualColumn - horzPageSize + 1;
            }
            else if (contentExtent.Width <= viewportSize.Width)
            {
                newLeftColumn = 0;
            }

            if (newLeftColumn != currentLeftColumn)
            {
                SetHorizontalOffset(newLeftColumn * Configurations.FormatFontWidth);
            }
        }
        //[Test]
        public void TestCharPosition19()
        {
            //Testing CharToVisualOffset if the line is empty
            TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");

            coordinates = new CharPosition(textBuffer);
            int offset = coordinates.CharToVisualOffset(4, 4);

            Assert.AreEqual(0, offset);
        }
        //[Test]
        public void TestCharPosition18()
        {
            //Testing that tab is converted to 4 characters by chartovisualoffset
            TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");

            coordinates = new CharPosition(textBuffer);
            int offset = coordinates.CharToVisualOffset(2, 2);

            Assert.AreEqual(8, offset);
        }
        //[Test]
        public void TestCharPosition22()
        {
            TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");

            coordinates = new CharPosition(textBuffer);
            int offset = coordinates.CharToVisualOffset(2, -1);

            Assert.AreEqual(0, offset);
            int charoffset = coordinates.VisualToCharOffset(2, offset);

            Assert.AreEqual(0, charoffset);
        }
        //[Test]
        public void TestCharPosition20()
        {
            //Testing VisualToCharOffset for tab character
            TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");

            coordinates = new CharPosition(textBuffer);
            int offset = coordinates.CharToVisualOffset(2, 2);

            Assert.AreEqual(8, offset);
            int charoffset = coordinates.VisualToCharOffset(2, offset);

            Assert.AreEqual(2, charoffset);
        }
Exemplo n.º 6
0
 public void TestCharPosition22()
 {
     TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");
     coordinates = new CharPosition(textBuffer);
     int offset = coordinates.CharToVisualOffset(2, -1);
     Assert.AreEqual(0, offset);
     int charoffset = coordinates.VisualToCharOffset(2, offset);
     Assert.AreEqual(0, charoffset);
 }
Exemplo n.º 7
0
 public void TestCharPosition21()
 {
     //Testing VisualToCharOffset if line is empty
     TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");
     coordinates = new CharPosition(textBuffer);
     int offset = coordinates.CharToVisualOffset(4, 4);
     int charoffset = coordinates.VisualToCharOffset(4, offset);
     Assert.AreEqual(0, charoffset);
 }
Exemplo n.º 8
0
 public void TestCharPosition20()
 {
     //Testing VisualToCharOffset for tab character
     TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");
     coordinates = new CharPosition(textBuffer);
     int offset = coordinates.CharToVisualOffset(2, 2);
     Assert.AreEqual(8, offset);
     int charoffset = coordinates.VisualToCharOffset(2, offset);
     Assert.AreEqual(2, charoffset);
 }
Exemplo n.º 9
0
 public void TestCharPosition18()
 {
     //Testing that tab is converted to 4 characters by chartovisualoffset
     TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld");
     coordinates = new CharPosition(textBuffer);
     int offset = coordinates.CharToVisualOffset(2, 2);
     Assert.AreEqual(8, offset);
 }