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); }
public override TextRange GetNextWord() { TextExtent currentWord = GetTextExtent(CurrentPosition); if (currentWord.Span.End < _textBuffer.AdvancedTextBuffer.CurrentSnapshot.Length) { // If the current point is at the end of the line, look for the next word on the next line if ((CurrentPosition == EndOfLine) && (CurrentPosition != _textBuffer.AdvancedTextBuffer.CurrentSnapshot.Length)) { TextPoint textPoint = Clone(); textPoint.MoveToBeginningOfNextLine(); textPoint.MoveTo(textPoint.StartOfLine); TextExtent wordOnNextLine = GetTextExtent(textPoint.CurrentPosition); if (wordOnNextLine.IsSignificant) { return(textPoint.GetCurrentWord()); } else if (wordOnNextLine.Span.End >= textPoint.EndOfLine) { return(textPoint.GetTextRange(textPoint.EndOfLine)); } return(textPoint.GetNextWord()); } // By default, VS stops at line breaks when determing word // boundaries. else if (ShouldStopAtEndOfLine(currentWord.Span.End) || IsCurrentWordABlankLine(currentWord)) { return(GetTextRange(currentWord.Span.End)); } TextExtent nextWord = GetTextExtent(currentWord.Span.End); if (!nextWord.IsSignificant) { nextWord = GetTextExtent(nextWord.Span.End); } int start = nextWord.Span.Start; int end = nextWord.Span.End; // The text structure navigator can return a word with whitespace attached at the end. // Handle that case here. start = Math.Max(start, currentWord.Span.End); TextPoint startPoint = Clone(); TextPoint endPoint = Clone(); startPoint.MoveTo(start); endPoint.MoveTo(end); return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, startPoint, endPoint)); } return(_bufferPrimitivesFactory.CreateTextRange(_textBuffer, TextBuffer.GetEndPoint(), TextBuffer.GetEndPoint())); }
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())); }
public override TextRange GetCurrentWord() { return(_bufferPoint.GetCurrentWord()); }