Beispiel #1
0
        /// <summary>
        /// Moves the caret to the next valid CaretPosition
        /// </summary>
        /// <returns>An CaretPosition containing the valid values of the caret after the move has occurred.</returns>
        /// <remarks>This method will take care of surrogate pairs and combining character sequences.</remarks>
        public CaretPosition MoveToNextCaretPosition()
        {
            CaretPosition oldPosition = this.Position;

            ITextViewLine line = _wpfTextView.GetTextViewLineContainingBufferPosition(oldPosition.BufferPosition);

            if (oldPosition.BufferPosition == line.End && line.IsLastTextViewLineForSnapshotLine)
            {
                //At the physical end of a line, either increase virtual space or move to the start of the next line.
                if (this.IsVirtualSpaceOrBoxSelectionEnabled)
                {
                    //Increase virtual spaces by one.
                    return(this.MoveTo(new VirtualSnapshotPoint(line.End, oldPosition.VirtualSpaces + 1)));
                }
                else if (oldPosition.BufferPosition == _wpfTextView.TextSnapshot.Length)
                {
                    return(oldPosition);
                }
                else
                {
                    //Move to the start of the next line (the position at the end of the line break is also the start of the next line).
                    return(this.MoveTo(line.EndIncludingLineBreak, PositionAffinity.Successor, true));
                }
            }
            else
            {
                //Not at the end of a line ... just move to the end of the current text element.
                SnapshotSpan textElementSpan = _wpfTextView.GetTextElementSpan(oldPosition.BufferPosition);
                return(this.MoveTo(textElementSpan.End, PositionAffinity.Successor, true));
            }
        }
Beispiel #2
0
        private void EnsureVirtualSelectedSpans()
        {
            if (_virtualSelectedSpans == null)
            {
                _virtualSelectedSpans = new List <VirtualSnapshotSpan>();
                if (this.IsEmpty)
                {
                    VirtualSnapshotPoint caretPoint = this.ActivePoint; //== this.AnchorPoint
                    _virtualSelectedSpans.Add(new VirtualSnapshotSpan(caretPoint, caretPoint));
                }
                else
                {
                    if (this.Mode == TextSelectionMode.Box)
                    {
                        SnapshotPoint        current = this.Start.Position;
                        VirtualSnapshotPoint end     = this.End;

                        do
                        {
                            ITextViewLine line = _wpfTextView.GetTextViewLineContainingBufferPosition(current);

                            VirtualSnapshotSpan?span = this.GetSelectionOnTextViewLine(line);
                            if (span.HasValue)
                            {
                                _virtualSelectedSpans.Add(span.Value);
                            }

                            if (line.LineBreakLength == 0 && line.IsLastTextViewLineForSnapshotLine)
                            {
                                break;      //Just processed last text view line in buffer.
                            }
                            current = line.EndIncludingLineBreak;
                        }while ((current.Position <= end.Position.Position) ||                              //Continue while the virtual space version of current
                                (end.IsInVirtualSpace && (current.Position == end.Position.Position)));     //is less than the virtual space position of the end of selection.
                    }
                    else
                    {
                        _virtualSelectedSpans.Add(new VirtualSnapshotSpan(this.Start, this.End));
                    }
                }
            }
        }