/// <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)); } }
internal void ToogleBookmark(Microsoft.VisualStudio.Text.Editor.CaretPosition caretPosition, int number) { int oldLine = -1; var point = caretPosition.BufferPosition; var line = point.GetContainingLine().LineNumber; ConcurrentDictionary <int, Bookmark> currentDico = null; if (NumberedBookmarksGlobalManager.IsAcrossDocuments) { } else { if (_dico == null) { _dico = new ConcurrentDictionary <int, Bookmark>(); } currentDico = _dico; } var oldBmk = NumberedBookmarksGlobalManager.ToogleBookmark(currentDico, this.buffer, point, number); if (oldBmk != null) { GetBookmarkManager(oldBmk.Buffer).DoBookmarksChanged(-1, oldBmk.Line); } DoBookmarksChanged(line, oldLine); }
/// <summary> /// Determines whether two <see cref="CaretPosition"/> objects are the same /// </summary> /// <returns><c>true</c> if the two objects are the same, otherwise <c>false</c>.</returns> public override bool Equals(object obj) { if (obj is CaretPosition) { CaretPosition caretPosition = (CaretPosition)obj; return(caretPosition == this); } else { return(false); } }
/// <summary> /// Moves the caret to the previous 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 MoveToPreviousCaretPosition() { CaretPosition oldPosition = this.Position; if (oldPosition.VirtualSpaces > 0) { ITextSnapshotLine line = _wpfTextView.TextSnapshot.GetLineFromPosition(oldPosition.BufferPosition); int newVirtualSpaces = this.IsVirtualSpaceOrBoxSelectionEnabled ? (oldPosition.VirtualSpaces - 1) : 0; return(this.MoveTo(new VirtualSnapshotPoint(line.End, newVirtualSpaces))); } else if (oldPosition.BufferPosition == 0) { return(oldPosition); } else { //Move to the start of the previous text element. SnapshotSpan textElementSpan = _wpfTextView.GetTextElementSpan(oldPosition.BufferPosition - 1); return(this.MoveTo(textElementSpan.Start, PositionAffinity.Successor, true)); } }
/// <summary> /// Initializes a new instance of <see cref="CaretPositionChangedEventArgs"/>. /// </summary> /// <param name="textView"> /// The <see cref="ITextView"/> that contains the caret. /// </param> /// <param name="oldPosition"> /// The old <see cref="CaretPosition"/>. /// </param> /// <param name="newPosition"> /// The new <see cref="CaretPosition"/>. /// </param> public CaretPositionChangedEventArgs(ITextView textView, CaretPosition oldPosition, CaretPosition newPosition) { _textView = textView; _oldPosition = oldPosition; _newPosition = newPosition; }
private void InternalMoveCaret(VirtualSnapshotPoint bufferPosition, PositionAffinity caretAffinity, ITextViewLine textLine, bool captureHorizontalPosition, bool captureVerticalPosition, bool raiseEvent) { CaretPosition oldPosition = this.Position; _caretAffinity = caretAffinity; _insertionPoint = bufferPosition; _forceVirtualSpace = _insertionPoint.IsInVirtualSpace && !this.IsVirtualSpaceOrBoxSelectionEnabled; _emptySelection = _wpfTextView.Selection.IsEmpty; _isContainedByView = (textLine.VisibilityState != VisibilityState.Unattached); double xCoordinate; double width; if (bufferPosition.IsInVirtualSpace || textLine.End == bufferPosition.Position) { //Never show overwrite caret when at the physical end of a line. this.OverwriteMode = false; } else { //Position is in the interior of the line ... preferred position is based strictly on the bufferPosition. this.OverwriteMode = _wpfTextView.Options.IsOverwriteModeEnabled() && _emptySelection; } // if we're in overwrite mode, draw a rectangle covering the text element, otherwise, just // draw a thin line if (_overwriteMode) { Microsoft.VisualStudio.Text.Formatting.TextBounds bounds = textLine.GetExtendedCharacterBounds(bufferPosition); xCoordinate = bounds.Left; width = bounds.Width; } else { xCoordinate = GetXCoordinateFromVirtualBufferPosition(textLine, bufferPosition); width = 10;//TODO: SystemParameters.CaretWidth; } _bounds = new SKRect((float)xCoordinate, (float)textLine.TextTop, (float)(xCoordinate + width), (float)textLine.TextBottom); CapturePreferredPositions(captureHorizontalPosition, captureVerticalPosition); CaretPosition newPosition = this.Position; if (newPosition != oldPosition) { this.UpdateBlinkTimer(); if (raiseEvent) { if (_selection.IsEmpty) { //Empty selections are logically located at the caret position, so force a selection changed event to be raised //before any of the caret position changed events. _selection.RaiseChangedEvent(emptyBefore: true, emptyAfter: true, moved: true); } // Inform this change to interested parties EventHandler <CaretPositionChangedEventArgs> positionChanged = this.PositionChanged; if (positionChanged != null) { _guardedOperations.RaiseEvent <CaretPositionChangedEventArgs>(this, positionChanged, new CaretPositionChangedEventArgs(_wpfTextView, oldPosition, newPosition)); } } } this.InvalidateVisual(); _updateNeeded = true; }