Ejemplo n.º 1
0
        /// <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);
                    }
                }
            }
        }
        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);
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public override bool Equals(object obj)
        {
            SimpleSelection other = obj as SimpleSelection;

            if (other == null)
            {
                return(false);
            }
            return(start.Equals(other.start) && end.Equals(other.end) &&
                   startOffset == other.startOffset && endOffset == other.endOffset &&
                   textArea == other.textArea);
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public override bool Equals(object obj)
        {
            SimpleSelection other = obj as SimpleSelection;

            if (other == null)
            {
                return(false);
            }
            if (IsEmpty && other.IsEmpty)
            {
                return(true);
            }
            return(this.startOffset == other.startOffset && this.endOffset == other.endOffset);
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        protected void OnMouseLeftButtonDowns(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;

                int i = 0;
                while (Char.IsWhiteSpace(textArea.Document.Text[currentSeg.Offset + i]) && i < currentSeg.Length)
                {
                    i++;
                }

                if (CaptureMouse())
                {
                    selecting      = true;
                    selectionStart = new AnchorSegment(Document, currentSeg.Offset + i, currentSeg.Length - i);
                    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(0.0);
                }
            }
        }
Ejemplo n.º 6
0
 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;
         }
     });
 }
		public void SelectionStart_ThreeCharactersSelectedInTextEditor_ConsoleTextEditorSelectionIsEqualToTextEditorSelection()
		{
			avalonEditTextEditor.Text = "te000xt";
			int startOffset = 2;
			int endOffset = 5;
			SimpleSelection expectedSelection = new SimpleSelection(startOffset, endOffset);
			avalonEditTextEditor.SelectionStart = expectedSelection.StartOffset;
			avalonEditTextEditor.SelectionLength = expectedSelection.Length;
			
			// Sanity check.
			Assert.AreEqual("000", avalonEditTextEditor.SelectedText);
			
			AssertSelectionsAreEqual(expectedSelection, consoleTextEditor);
		}
		public void SelectionLength_NothingSelectedInTextEditor_ConsoleTextEditorSelectionMatchesTextEditorSelection()
		{
			avalonEditTextEditor.Text = "text";
			avalonEditTextEditor.TextArea.Caret.Column = 1;
			avalonEditTextEditor.SelectionLength = 0;
			
			SimpleSelection expectedSelection = new SimpleSelection(1, 1);
			AssertSelectionsAreEqual(expectedSelection, consoleTextEditor);
		}
		void AssertSelectionsAreEqual(SimpleSelection expectedSelection, IScriptingConsoleTextEditor consoleTextEditor)
		{
			int selectionLength = consoleTextEditor.SelectionStart + consoleTextEditor.SelectionLength;
			SimpleSelection actualSelection = new SimpleSelection(consoleTextEditor.SelectionStart, selectionLength);
			Assert.AreEqual(expectedSelection, actualSelection);
		}
Ejemplo n.º 10
0
		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;
				}
			};
		}
Ejemplo n.º 11
0
		public void JumpTo(int line, int column)
		{
			locationJumpedTo = new Location(column, line);
			selection = new SimpleSelection(-1, -1);
		}
Ejemplo n.º 12
0
		public void Select(int selectionStart, int selectionLength)
		{
			selection = new SimpleSelection(selectionStart, selectionLength + selectionStart);
		}
Ejemplo n.º 13
0
        private 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
                        if (endPos.Column == 1)
                        {
                            var a = textArea.Document.GetLineByNumber(textArea.Caret.Line);

                            var b = a.PreviousLine;
                            if (b != null)
                            {
                                var c = b.PreviousLine;
                                if (b.obs != null)
                                {
                                    var obs = c.obs;
                                    var sa = textArea.Document.Text.Substring(a.Offset, a.Length + a.DelimiterLength);
                                    var bs = textArea.Document.Text.Substring(b.Offset, b.Length + b.DelimiterLength);
                                    var cs = textArea.Document.Text.Substring(c.Offset, c.Length + c.DelimiterLength);
                                    textArea.Document.Remove(c.Offset + c.Length, bs.Length + sa.Length /* + c.DelimiterLength*//* + a.DelimiterLength + b.DelimiterLength*/);
                                    textArea.Document.Insert(c.Offset + c.Length, sa);
                                }
                                else
                                {
                                    var sel = new SimpleSelection(textArea, startPos, endPos);
                                    sel.ReplaceSelectionWithText(string.Empty);
                                }
                            }
                            else
                            {
                                var sel = new SimpleSelection(textArea, startPos, endPos);
                                sel.ReplaceSelectionWithText(string.Empty);
                            }
                        }
                        else
                        {
                            var sel = new SimpleSelection(textArea, startPos, endPos);
                            sel.ReplaceSelectionWithText(string.Empty);
                        }
                    }
                    else
                    {
                        textArea.RemoveSelectedText();
                    }
                }
                textArea.Caret.BringCaretToView();
                args.Handled = true;
            });
        }