/// <summary> /// Handler for ITextView.BringLineIntoViewCompleted event. /// </summary> private static void HandleSelectByLineCompleted(object sender, BringLineIntoViewCompletedEventArgs e) { TextEditor This; Invariant.Assert(sender is ITextView); ((ITextView)sender).BringLineIntoViewCompleted -= new BringLineIntoViewCompletedEventHandler(HandleSelectByLineCompleted); if (e != null && !e.Cancelled && e.Error == null) { This = e.UserState as TextEditor; if (This == null || !This._IsEnabled) { return; } TextEditorTyping._FlushPendingInputItems(This); using (This.Selection.DeclareChangeBlock()) { // Update suggestedX TextEditorSelection.UpdateSuggestedXOnColumnOrPageBoundary(This, e.NewSuggestedX); int newComparedToOld = e.NewPosition.CompareTo(e.Position); if (e.Count < 0) // Moving up if count < 0, moving down otherwise { // Shift key is down - Extend the selection edge if (newComparedToOld < 0 || newComparedToOld == 0 && e.NewPosition.LogicalDirection != e.Position.LogicalDirection) { // Note: we compare orientations of equal positions to handle a case // when original position was at the end of line (after its linebreak with backward orientation) // as a result of Shift+End selection; and the new position is in the beginning of the next line, // which is essentially the same position but oriented differently. // In such a case the new position is good enough to go there. // We certainly don't want to go to the end of the document in this case. // We have another line in a given direction; move to it ExtendSelectionAndBringIntoView(e.NewPosition, This); } else { // Remember where we were so that we can return if a line down follows. if (This._NextLineAdvanceMovingPosition == null) { This._NextLineAdvanceMovingPosition = e.Position; This._IsNextLineAdvanceMovingPositionAtDocumentHead = true; } // No more lines in this direction. Move to start of current line. ExtendSelectionAndBringIntoView(GetPositionAtLineStart(e.NewPosition), This); } } else { AdjustMovingPositionForSelectDownByLine(This, e.NewPosition, e.Position, e.NewSuggestedX); } } } }
/// <summary> /// Fires BringLineIntoViewCompleted event. /// </summary> /// <param name="e">Event arguments for the BringLineIntoViewCompleted event.</param> protected virtual void OnBringLineIntoViewCompleted(BringLineIntoViewCompletedEventArgs e) { if (this.BringLineIntoViewCompleted != null) { this.BringLineIntoViewCompleted(this, e); } }
/// <summary> /// Handler for ITextView.BringLineIntoViewCompleted event. /// </summary> private static void HandleMoveByLineCompleted(object sender, BringLineIntoViewCompletedEventArgs e) { Invariant.Assert(sender is ITextView); ((ITextView)sender).BringLineIntoViewCompleted -= new BringLineIntoViewCompletedEventHandler(HandleMoveByLineCompleted); if (e != null && !e.Cancelled && e.Error == null) { TextEditor This = e.UserState as TextEditor; if (This == null || !This._IsEnabled) { return; } TextEditorTyping._FlushPendingInputItems(This); using (This.Selection.DeclareChangeBlock()) { // Update suggestedX TextEditorSelection.UpdateSuggestedXOnColumnOrPageBoundary(This, e.NewSuggestedX); // Move insertion point to next or previous line This.Selection.SetCaretToPosition(e.NewPosition, e.NewPosition.LogicalDirection, /*allowStopAtLineEnd:*/true, /*allowStopNearSpace:*/true); } } }