/// <inheritdoc/>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            if (!e.Handled && TextView != null && textArea != null)
            {
                e.Handled = true;
                textArea.Focus();

                SimpleSegment currentSeg = GetTextLineSegment(e);
                if (currentSeg == SimpleSegment.Invalid)
                {
                    return;
                }
                textArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
                if (CaptureMouse())
                {
                    selecting      = true;
                    selectionStart = new AnchorSegment(Document, currentSeg.Offset, currentSeg.Length);
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        SimpleSelection simpleSelection = textArea.Selection as SimpleSelection;
                        if (simpleSelection != null)
                        {
                            selectionStart = new AnchorSegment(Document, simpleSelection.SurroundingSegment);
                        }
                    }
                    textArea.Selection = Selection.Create(textArea, selectionStart);
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        ExtendSelection(currentSeg);
                    }
                    textArea.Caret.BringCaretToView(5.0);
                }
            }
        }
Exemple #2
0
        static void OnSelectAll(object target, ExecutedRoutedEventArgs args)
        {
            TextArea textArea = GetTextArea(target);

            if (textArea != null && textArea.Document != null)
            {
                args.Handled          = true;
                textArea.Caret.Offset = textArea.Document.TextLength;
                textArea.Selection    = SimpleSelection.Create(textArea, 0, textArea.Document.TextLength);
            }
        }
Exemple #3
0
        /// <inheritdoc/>
        public override bool Equals(object obj)
        {
            SimpleSelection other = obj as SimpleSelection;

            if (other == null)
            {
                return(false);
            }
            return(this.start.Equals(other.start) && this.end.Equals(other.end) &&
                   this.startOffset == other.startOffset && this.endOffset == other.endOffset &&
                   this.textArea == other.textArea);
        }
 static ExecutedRoutedEventHandler OnDelete(CaretMovementType caretMovement)
 {
     return((target, args) => {
         TextArea textArea = GetTextArea(target);
         if (textArea != null && textArea.Document != null)
         {
             if (textArea.Selection.IsEmpty)
             {
                 TextViewPosition startPos = textArea.Caret.Position;
                 bool enableVirtualSpace = textArea.Options.EnableVirtualSpace;
                 // When pressing delete; don't move the caret further into virtual space - instead delete the newline
                 if (caretMovement == CaretMovementType.CharRight)
                 {
                     enableVirtualSpace = false;
                 }
                 double desiredXPos = textArea.Caret.DesiredXPos;
                 TextViewPosition endPos = CaretNavigationCommandHandler.GetNewCaretPosition(
                     textArea.TextView, startPos, caretMovement, enableVirtualSpace, ref desiredXPos);
                 // GetNewCaretPosition may return (0,0) as new position,
                 // thus we need to validate endPos before using it in the selection.
                 if (endPos.Line < 1 || endPos.Column < 1)
                 {
                     endPos = new TextViewPosition(Math.Max(endPos.Line, 1), Math.Max(endPos.Column, 1));
                 }
                 // Don't select the text to be deleted; just reuse the ReplaceSelectionWithText logic
                 var sel = new SimpleSelection(textArea, startPos, endPos);
                 sel.ReplaceSelectionWithText(string.Empty);
             }
             else
             {
                 textArea.RemoveSelectedText();
             }
             textArea.Caret.BringCaretToView();
             args.Handled = true;
         }
     });
 }