예제 #1
0
        public void TryGetPreviousPointOnLine1()
        {
            Create("foo", "bar");
            var point = _textBuffer.GetLine(0).End.Subtract(1);
            var res   = SnapshotPointUtil.TryGetPreviousPointOnLine(point, 1);

            Assert.True(res.IsSome());
            Assert.Equal(point.Subtract(1), res.Value);
        }
예제 #2
0
        public void GetPoints7()
        {
            Create("foo bar");
            var start  = _textBuffer.CurrentSnapshot.GetLineRange(0).End;
            var points = SnapshotPointUtil.GetPoints(Path.Backward, start);
            var str    = points.Select(x => x.GetChar().ToString()).Aggregate((x, y) => x + y);

            Assert.Equal("rab oof", str);
        }
예제 #3
0
        public void TryGetNextPointOnLine3()
        {
            Create("foo", "bar");
            var point = _textBuffer.GetLine(0).Start.Add(1);
            var res   = SnapshotPointUtil.TryGetNextPointOnLine(point, 1);

            Assert.True(res.IsSome());
            Assert.Equal(point.Add(1), res.Value);
        }
예제 #4
0
        public void GetPoints3()
        {
            Create("foo bar");
            var start  = SnapshotUtil.GetStartPoint(_textBuffer.CurrentSnapshot);
            var points = SnapshotPointUtil.GetPoints(Path.Forward, start);
            var str    = points.Select(x => x.GetChar().ToString()).Aggregate((x, y) => x + y);

            Assert.Equal("foo bar", str);
        }
예제 #5
0
        public void GetNextPointWithWrap2()
        {
            Create("foo", "bar");
            var line = _textBuffer.CurrentSnapshot.GetLineFromLineNumber(0);
            var next = SnapshotPointUtil.GetNextPointWithWrap(line.End);

            line = _textBuffer.CurrentSnapshot.GetLineFromLineNumber(1);
            Assert.Equal(line.Start, next);
        }
예제 #6
0
        public void GetLineRangeSpan2()
        {
            Create(s_lines);
            var span     = SnapshotPointUtil.GetLineRangeSpan(new SnapshotPoint(_snapshot, 0), 2);
            var start    = _snapshot.GetLineFromLineNumber(0);
            var second   = _snapshot.GetLineFromLineNumber(1);
            var expected = new Span(start.Start, second.End - start.Start);

            Assert.AreEqual(span.Span, expected);
        }
예제 #7
0
        public void GetPoints4()
        {
            Create("foo", "bar");
            var start = SnapshotUtil.GetStartPoint(_textBuffer.CurrentSnapshot);

            foreach (var cur in SnapshotPointUtil.GetPoints(Path.Forward, start))
            {
                var notUsed = cur.GetChar();
            }
        }
예제 #8
0
        public void GetLines2()
        {
            Create("foo", "bar", "baz");
            var point = new SnapshotPoint(_snapshot, 6);
            var agg   = SnapshotPointUtil.GetLines(point, Path.Forward)
                        .Select(x => x.GetText())
                        .Aggregate((x, y) => x + y);

            Assert.AreEqual("barbaz", agg);
        }
예제 #9
0
        public void MoveCaretToMotionResult12()
        {
            Create("dog", "cat", "bear");
            var data = VimUtil.CreateMotionResult(
                _textBuffer.GetLineRange(0, 1).ExtentIncludingLineBreak,
                false,
                MotionKind.NewLineWise(CaretColumn.NewInLastLine(2)));

            _operations.MoveCaretToMotionResult(data);
            Assert.AreEqual(Tuple.Create(0, 2), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
        }
예제 #10
0
        public void MoveCaretToMotionResult11()
        {
            Create("dog", "cat", "bear");
            var data = VimUtil.CreateMotionResult(
                _textBuffer.GetLineRange(0, 1).Extent,
                false,
                MotionKind.CharacterWiseInclusive);

            _operations.MoveCaretToMotionResult(data);
            Assert.AreEqual(Tuple.Create(0, 0), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
        }
예제 #11
0
        public void MoveCaretToMotionResult10()
        {
            Create("foo", "bar", "");
            var data = VimUtil.CreateMotionResult(
                _textBuffer.GetLineRange(0, 1).Extent,
                true,
                MotionKind.NewLineWise(CaretColumn.NewInLastLine(0)));

            _operations.MoveCaretToMotionResult(data);
            Assert.AreEqual(Tuple.Create(1, 0), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
        }
예제 #12
0
        public static TextSpan ToTextSpan(this SnapshotSpan span)
        {
            var start  = SnapshotPointUtil.GetLineColumn(span.Start);
            var option = SnapshotSpanUtil.GetLastIncludedPoint(span);
            var end    = option.IsSome()
                ? SnapshotPointUtil.GetLineColumn(option.Value)
                : start;

            return(new TextSpan
            {
                iStartLine = start.Item1,
                iStartIndex = start.Item2,
                iEndLine = end.Item1,
                iEndIndex = end.Item2
            });
        }
예제 #13
0
        public void GetCharOrDefault2()
        {
            Create("foo", "bar");
            var endPoint = new SnapshotPoint(_textBuffer.CurrentSnapshot, _textBuffer.CurrentSnapshot.Length);
            var didSee   = false;

            try
            {
                var notUsed = endPoint.GetChar();
            }
            catch (ArgumentException)
            {
                didSee = true;
            }
            Assert.IsTrue(didSee);
            Assert.AreEqual('f', SnapshotPointUtil.GetCharOrDefault(endPoint, 'f'));
        }
예제 #14
0
파일: TextManager.cs 프로젝트: d8q8/VsVim
        internal bool NavigateTo(VirtualSnapshotPoint point)
        {
            var tuple    = SnapshotPointUtil.GetLineColumn(point.Position);
            var line     = tuple.Item1;
            var column   = tuple.Item2;
            var vsBuffer = _vsAdapter.EditorAdapter.GetBufferAdapter(point.Position.Snapshot.TextBuffer);
            var viewGuid = VSConstants.LOGVIEWID_Code;
            var hr       = _textManager.NavigateToLineAndColumn(
                vsBuffer,
                ref viewGuid,
                line,
                column,
                line,
                column);

            return(ErrorHandler.Succeeded(hr));
        }
예제 #15
0
        public bool NavigateTo(VirtualSnapshotPoint point)
        {
            var tuple    = SnapshotPointUtil.GetLineNumberAndOffset(point.Position);
            var line     = tuple.Item1;
            var column   = tuple.Item2;
            var buffer   = point.Position.Snapshot.TextBuffer;
            var fileName = GetName(buffer);

            try
            {
                IdeApp.Workbench.OpenDocument(fileName, null, line, column).Wait(System.Threading.CancellationToken.None);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #16
0
 /// <summary>
 /// Get the column hat this SnapshotPoint occupies
 /// </summary>
 public static int GetColumn(this SnapshotPoint point)
 {
     return(SnapshotPointUtil.GetColumn(point));
 }