ClearSelection() 공개 메소드

Clears the current selection.
public ClearSelection ( ) : void
리턴 void
 static ExecutedRoutedEventHandler OnMoveCaret(CaretMovementType direction)
 {
     return((target, args) => {
         TextArea textArea = GetTextArea(target);
         if (textArea != null && textArea.Document != null)
         {
             args.Handled = true;
             textArea.ClearSelection();
             MoveCaret(textArea, direction);
             textArea.Caret.BringCaretToView();
         }
     });
 }
예제 #2
0
 static ExecutedRoutedEventHandler OnDelete(RoutedUICommand selectingCommand)
 {
     return((target, args) =>
     {
         TextArea textArea = GetTextArea(target);
         if (textArea != null && textArea.Document != null)
         {
             // call BeginUpdate before running the 'selectingCommand'
             // so that undoing the delete does not select the deleted character
             using (textArea.Document.RunUpdate())
             {
                 if (textArea.Selection.IsEmpty)
                 {
                     TextViewPosition oldCaretPosition = textArea.Caret.Position;
                     if (textArea.Caret.IsInVirtualSpace && selectingCommand == EditingCommands.SelectRightByCharacter)
                     {
                         EditingCommands.SelectRightByWord.Execute(args.Parameter, textArea);
                     }
                     else
                     {
                         selectingCommand.Execute(args.Parameter, textArea);
                     }
                     bool hasSomethingDeletable = false;
                     foreach (ISegment s in textArea.Selection.Segments)
                     {
                         if (textArea.GetDeletableSegments(s).Length > 0)
                         {
                             hasSomethingDeletable = true;
                             break;
                         }
                     }
                     if (!hasSomethingDeletable)
                     {
                         // If nothing in the selection is deletable; then reset caret+selection
                         // to the previous value. This prevents the caret from moving through read-only sections.
                         textArea.Caret.Position = oldCaretPosition;
                         textArea.ClearSelection();
                     }
                 }
                 textArea.RemoveSelectedText();
             }
             textArea.Caret.BringCaretToView();
             args.Handled = true;
         }
     });
 }
예제 #3
0
 static ExecutedRoutedEventHandler OnMoveCaret(CaretMovementType direction)
 {
     return((target, args) =>
     {
         TextArea textArea = GetTextArea(target);
         if (textArea != null && textArea.Document != null)
         {
             switch (direction)
             {
             case CaretMovementType.LineUp:
             case CaretMovementType.LineDown:
                 if (textArea.IsCodeCompleteMode)
                 {
                     return;
                 }
                 break;
             }
             args.Handled = true;
             textArea.ClearSelection();
             MoveCaret(textArea, direction);
             textArea.Caret.BringCaretToView();
         }
     });
 }
예제 #4
0
        void textArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            mode = SelectionMode.None;
            if (!e.Handled && e.ChangedButton == MouseButton.Left)
            {
                ModifierKeys modifiers = Keyboard.Modifiers;
                bool         shift     = (modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
                if (enableTextDragDrop && e.ClickCount == 1 && !shift)
                {
                    int visualColumn;
                    int offset = GetOffsetFromMousePosition(e, out visualColumn);
                    if (textArea.Selection.Contains(offset))
                    {
                        if (textArea.CaptureMouse())
                        {
                            mode = SelectionMode.PossibleDragStart;
                            possibleDragStartMousePos = e.GetPosition(textArea);
                        }
                        e.Handled = true;
                        return;
                    }
                }

                var oldPosition = textArea.Caret.Position;
                SetCaretOffsetToMousePosition(e);


                if (!shift)
                {
                    textArea.ClearSelection();
                }
                if (textArea.CaptureMouse())
                {
                    if ((modifiers & ModifierKeys.Alt) == ModifierKeys.Alt && textArea.Options.EnableRectangularSelection)
                    {
                        mode = SelectionMode.Rectangular;
                        if (shift && textArea.Selection is RectangleSelection)
                        {
                            textArea.Selection = textArea.Selection.StartSelectionOrSetEndpoint(oldPosition, textArea.Caret.Position);
                        }
                    }
                    else if (e.ClickCount == 1 && ((modifiers & ModifierKeys.Control) == 0))
                    {
                        mode = SelectionMode.Normal;
                        if (shift && !(textArea.Selection is RectangleSelection))
                        {
                            textArea.Selection = textArea.Selection.StartSelectionOrSetEndpoint(oldPosition, textArea.Caret.Position);
                        }
                    }
                    else
                    {
                        SimpleSegment startWord;
                        if (e.ClickCount == 3)
                        {
                            mode      = SelectionMode.WholeLine;
                            startWord = GetLineAtMousePosition(e);
                        }
                        else
                        {
                            mode      = SelectionMode.WholeWord;
                            startWord = GetWordAtMousePosition(e);
                        }
                        if (startWord == SimpleSegment.Invalid)
                        {
                            mode = SelectionMode.None;
                            textArea.ReleaseMouseCapture();
                            return;
                        }
                        if (shift && !textArea.Selection.IsEmpty)
                        {
                            if (startWord.Offset < textArea.Selection.SurroundingSegment.Offset)
                            {
                                textArea.Selection = textArea.Selection.SetEndpoint(new TextViewPosition(textArea.Document.GetLocation(startWord.Offset)));
                            }
                            else if (startWord.EndOffset > textArea.Selection.SurroundingSegment.EndOffset)
                            {
                                textArea.Selection = textArea.Selection.SetEndpoint(new TextViewPosition(textArea.Document.GetLocation(startWord.EndOffset)));
                            }
                            this.startWord = new AnchorSegment(textArea.Document, textArea.Selection.SurroundingSegment);
                        }
                        else
                        {
                            textArea.Selection = Selection.Create(textArea, startWord.Offset, startWord.EndOffset);
                            this.startWord     = new AnchorSegment(textArea.Document, startWord.Offset, startWord.Length);
                        }
                    }
                }
            }
            e.Handled = true;
        }