Пример #1
0
        CaretPosition MoveTo(ITextViewLine textLine, double xCoordinate, bool captureHorizontalPosition, bool captureVerticalPosition, bool canAutoIndent)
        {
            if (textLine == null)
            {
                throw new ArgumentNullException(nameof(textLine));
            }

            bool filterPos = true;

            // Don't auto indent if it's at column 0
            if (canAutoIndent && CanAutoIndent(textLine) && xCoordinate > textLine.TextRight)
            {
                var wpfView = textView as IWpfTextView;
                if (wpfView != null)
                {
                    int indentation = IndentHelper.GetDesiredIndentation(textView, smartIndentationService, textLine.Start.GetContainingLine()) ?? 0;
                    var textBounds  = textLine.GetExtendedCharacterBounds(new VirtualSnapshotPoint(textLine.Start, indentation));
                    xCoordinate = textBounds.Leading;
                    filterPos   = false;
                }
            }

            var bufferPosition = textLine.GetInsertionBufferPositionFromXCoordinate(xCoordinate);

            Affinity = textLine.IsLastTextViewLineForSnapshotLine || bufferPosition.Position != textLine.End ? PositionAffinity.Successor : PositionAffinity.Predecessor;
            if (filterPos)
            {
                bufferPosition = FilterColumn(bufferPosition);
            }
            SetExplicitPosition(bufferPosition);
            if (captureHorizontalPosition)
            {
                preferredXCoordinate = Left;
            }
            if (captureVerticalPosition)
            {
                SavePreferredYCoordinate();
            }
            return(Position);
        }
Пример #2
0
 public int?GetDesiredIndentation(ITextSnapshotLine line) => IndentHelper.GetDesiredBlockIndentation(textView, line);