Exemplo n.º 1
0
        public override bool Capitalize()
        {
            int startPosition = _startPoint.CurrentPosition;

            if (IsEmpty)
            {
                int       endPosition   = _endPoint.CurrentPosition;
                TextRange currentWord   = _startPoint.GetCurrentWord();
                string    nextCharacter = _startPoint.GetNextCharacter();
                if (_startPoint.CurrentPosition == currentWord.GetStartPoint().CurrentPosition)
                {
                    nextCharacter = nextCharacter.ToUpper(CultureInfo.CurrentCulture);
                }
                else
                {
                    nextCharacter = nextCharacter.ToLower(CultureInfo.CurrentCulture);
                }
                if (!PrimitivesUtilities.Replace(TextBuffer.AdvancedTextBuffer, new Span(_startPoint.CurrentPosition, nextCharacter.Length), nextCharacter))
                {
                    return(false);
                }
                _endPoint.MoveTo(endPosition);
            }
            else
            {
                using (ITextEdit edit = TextBuffer.AdvancedTextBuffer.CreateEdit())
                {
                    TextRange currentWord = _startPoint.GetCurrentWord();

                    // If the current word extends past this range, go to the next word
                    if (currentWord.GetStartPoint().CurrentPosition < _startPoint.CurrentPosition)
                    {
                        currentWord = currentWord.GetEndPoint().GetNextWord();
                    }

                    while (currentWord.GetStartPoint().CurrentPosition < _endPoint.CurrentPosition)
                    {
                        string wordText     = currentWord.GetText();
                        string startElement = StringInfo.GetNextTextElement(wordText);
                        wordText = startElement.ToUpper(CultureInfo.CurrentCulture) + wordText.Substring(startElement.Length).ToLower(CultureInfo.CurrentCulture);
                        if (!edit.Replace(currentWord.AdvancedTextRange.Span, wordText))
                        {
                            edit.Cancel();
                            return(false);
                        }

                        currentWord = currentWord.GetEndPoint().GetNextWord();
                    }

                    edit.Apply();

                    if (edit.Canceled)
                    {
                        return(false);
                    }
                }
            }
            _startPoint.MoveTo(startPosition);
            return(true);
        }
Exemplo n.º 2
0
        public override void MoveTo(TextRange newRange)
        {
            if (newRange.TextBuffer != TextBuffer)
            {
                throw new ArgumentException(Strings.OtherRangeFromWrongBuffer);
            }

            _startPoint = newRange.GetStartPoint();
            _endPoint   = newRange.GetEndPoint();
        }
        public override void MoveToNextWord()
        {
            if (CurrentPosition != _textBuffer.AdvancedTextBuffer.CurrentSnapshot.Length)
            {
                TextRange nextWord = GetNextWord();

                if (nextWord.GetStartPoint().CurrentPosition == CurrentPosition)
                {
                    MoveTo(nextWord.GetEndPoint().CurrentPosition);
                }
                else
                {
                    MoveTo(nextWord.GetStartPoint().CurrentPosition);
                }
            }
        }
        public override TextRange GetPreviousWord()
        {
            TextRange currentWord = GetCurrentWord();

            if (currentWord.GetStartPoint().CurrentPosition > 0)
            {
                // By default, VS stops at line breaks when determing word
                // boundaries.
                if ((currentWord.GetStartPoint().CurrentPosition == StartOfLine) &&
                    (CurrentPosition != StartOfLine))
                {
                    return(GetTextRange(currentWord.GetStartPoint()));
                }

                // If the point is at the end of a word that is not whitespace, it is possible
                // that the "current word" is also the previous word in standard VS.
                if ((currentWord.GetEndPoint().CurrentPosition == CurrentPosition) &&
                    (!currentWord.IsEmpty))
                {
                    return(currentWord);
                }

                TextPoint pointInPreviousWord = currentWord.GetStartPoint();
                pointInPreviousWord.MoveTo(pointInPreviousWord.CurrentPosition - 1);

                TextRange previousWord = pointInPreviousWord.GetCurrentWord();

                if (previousWord.GetStartPoint().CurrentPosition > 0)
                {
                    if (ShouldContinuePastPreviousWord(previousWord))
                    {
                        pointInPreviousWord.MoveTo(previousWord.GetStartPoint().CurrentPosition - 1);
                        previousWord = pointInPreviousWord.GetCurrentWord();
                    }
                }

                return(previousWord);
            }

            return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, TextBuffer.GetStartPoint(), TextBuffer.GetStartPoint()));
        }
Exemplo n.º 5
0
 public override DisplayTextPoint GetDisplayEndPoint()
 {
     return(TextView.GetTextPoint(_bufferRange.GetEndPoint()));
 }
Exemplo n.º 6
0
 public override void MoveTo(TextRange newRange)
 {
     SetStart(newRange.GetStartPoint());
     SetEnd(newRange.GetEndPoint());
 }
 public override void SelectRange(TextRange textRange)
 {
     this.SelectRange(textRange.GetStartPoint().CurrentPosition, textRange.GetEndPoint().CurrentPosition);
 }
 public override TextPoint GetEndPoint()
 {
     return(TextRange.GetEndPoint());
 }