Example #1
0
            public SnapshotSpan GetTextElementSpan(SnapshotPoint bufferPosition)
            {
                bufferPosition = this.FixBufferPosition(bufferPosition);
                if (!this.ContainsBufferPosition(bufferPosition))
                {
                    throw new ArgumentOutOfRangeException(nameof(bufferPosition));
                }

                if (bufferPosition >= ExtentIncludingLineBreak.End - lineBreakLength)
                {
                    return(new SnapshotSpan(ExtentIncludingLineBreak.End - lineBreakLength, lineBreakLength));
                }

                var c = textEditor.GetCharAt(bufferPosition.Position);

                if ((c & CaretMoveActions.LowSurrogateMarker) == CaretMoveActions.LowSurrogateMarker)
                {
                    return(new SnapshotSpan(bufferPosition.Snapshot, bufferPosition.Position, 2));
                }
                if ((c & CaretMoveActions.HighSurrogateMarker) == CaretMoveActions.HighSurrogateMarker)
                {
                    return(new SnapshotSpan(bufferPosition.Snapshot, bufferPosition.Position - 1, 2));
                }
                return(new SnapshotSpan(bufferPosition, 1));
            }
Example #2
0
            public SnapshotSpan GetTextElementSpan(SnapshotPoint bufferPosition)
            {
                bufferPosition = this.FixBufferPosition(bufferPosition);
                if (!this.ContainsBufferPosition(bufferPosition))
                {
                    throw new ArgumentOutOfRangeException(nameof(bufferPosition));
                }

                if (bufferPosition >= ExtentIncludingLineBreak.End - lineBreakLength)
                {
                    return(new SnapshotSpan(ExtentIncludingLineBreak.End - lineBreakLength, lineBreakLength));
                }
                var line       = textEditor.GetLineByOffset(bufferPosition.Position);
                var lineOffset = line.Offset;

                var highlightedLine = this.textEditor.Document.SyntaxMode.GetHighlightedLineAsync(line, default(CancellationToken)).WaitAndGetResult();

                if (highlightedLine != null)
                {
                    foreach (var seg in highlightedLine.Segments)
                    {
                        if (seg.Contains(bufferPosition - lineOffset))
                        {
                            return(new SnapshotSpan(bufferPosition.Snapshot, lineOffset + seg.Offset, seg.Length));
                        }
                    }
                }

                var c = textEditor.GetCharAt(bufferPosition.Position);

                if ((c & CaretMoveActions.LowSurrogateMarker) == CaretMoveActions.LowSurrogateMarker)
                {
                    return(new SnapshotSpan(bufferPosition.Snapshot, bufferPosition.Position, 2));
                }
                if ((c & CaretMoveActions.HighSurrogateMarker) == CaretMoveActions.HighSurrogateMarker)
                {
                    return(new SnapshotSpan(bufferPosition.Snapshot, bufferPosition.Position - 1, 2));
                }
                return(new SnapshotSpan(bufferPosition, 1));
            }