Exemple #1
0
        /// <summary>
        /// Creates a new TextArea instance.
        /// </summary>
        protected TextArea(TextView textView)
        {
            TextView = textView ?? throw new ArgumentNullException(nameof(textView));
            Options  = textView.Options;

            _selection = EmptySelection = new EmptySelection(this);

            textView.Services.AddService(this);

            textView.LineTransformers.Add(new SelectionColorizer(this));
            textView.InsertLayer(new SelectionLayer(this), KnownLayer.Selection, LayerInsertionPosition.Replace);

            Caret = new Caret(this);
            Caret.PositionChanged += (sender, e) => RequestSelectionValidation();
            Caret.PositionChanged += CaretPositionChanged;
            AttachTypingEvents();

            LeftMargins.CollectionChanged += LeftMargins_CollectionChanged;

            DefaultInputHandler = new TextAreaDefaultInputHandler(this);
            ActiveInputHandler  = DefaultInputHandler;

            textView.GetObservableWithHistory(TextBlock.FontSizeProperty).Subscribe(fontSizeChange =>
            {
                TextView.SetScrollOffset(new Vector(_offset.X, _offset.Y * TextView.DefaultLineHeight));
            });
        }
        static EditingCommandHandler()
        {
            AddBinding(EditingCommands.Delete, InputModifiers.None, Key.Delete, OnDelete(CaretMovementType.CharRight));
            AddBinding(EditingCommands.DeleteNextWord, InputModifiers.Control, Key.Delete,
                       OnDelete(CaretMovementType.WordRight));
            AddBinding(EditingCommands.Backspace, InputModifiers.None, Key.Back, OnDelete(CaretMovementType.Backspace));
            KeyBindings.Add(
                TextAreaDefaultInputHandler.CreateKeyBinding(EditingCommands.Backspace, InputModifiers.Shift,
                                                             Key.Back)); // make Shift-Backspace do the same as plain backspace
            AddBinding(EditingCommands.DeletePreviousWord, InputModifiers.Control, Key.Back,
                       OnDelete(CaretMovementType.WordLeft));
            AddBinding(EditingCommands.EnterParagraphBreak, InputModifiers.None, Key.Enter, OnEnter);
            AddBinding(EditingCommands.EnterLineBreak, InputModifiers.Shift, Key.Enter, OnEnter);
            AddBinding(EditingCommands.TabForward, InputModifiers.None, Key.Tab, OnTab);
            AddBinding(EditingCommands.TabBackward, InputModifiers.Shift, Key.Tab, OnShiftTab);

            AddBinding(ApplicationCommands.Copy, OnCopy, CanCutOrCopy);
            AddBinding(ApplicationCommands.Cut, OnCut, CanCutOrCopy);
            AddBinding(ApplicationCommands.Paste, OnPaste, CanPaste);

            AddBinding(AvaloniaEditCommands.ToggleOverstrike, OnToggleOverstrike);
            AddBinding(AvaloniaEditCommands.DeleteLine, OnDeleteLine);

            AddBinding(AvaloniaEditCommands.RemoveLeadingWhitespace, OnRemoveLeadingWhitespace);
            AddBinding(AvaloniaEditCommands.RemoveTrailingWhitespace, OnRemoveTrailingWhitespace);
            AddBinding(AvaloniaEditCommands.ConvertToUppercase, OnConvertToUpperCase);
            AddBinding(AvaloniaEditCommands.ConvertToLowercase, OnConvertToLowerCase);
            AddBinding(AvaloniaEditCommands.ConvertToTitleCase, OnConvertToTitleCase);
            AddBinding(AvaloniaEditCommands.InvertCase, OnInvertCase);
            AddBinding(AvaloniaEditCommands.ConvertTabsToSpaces, OnConvertTabsToSpaces);
            AddBinding(AvaloniaEditCommands.ConvertSpacesToTabs, OnConvertSpacesToTabs);
            AddBinding(AvaloniaEditCommands.ConvertLeadingTabsToSpaces, OnConvertLeadingTabsToSpaces);
            AddBinding(AvaloniaEditCommands.ConvertLeadingSpacesToTabs, OnConvertLeadingSpacesToTabs);
            AddBinding(AvaloniaEditCommands.IndentSelection, OnIndentSelection);
        }
Exemple #3
0
        /// <summary>
        /// Creates a new TextArea instance.
        /// </summary>
        protected TextArea(TextView textView)
        {
            TextView = textView ?? throw new ArgumentNullException(nameof(textView));
            Options  = textView.Options;

            _selection = EmptySelection = new EmptySelection(this);

            textView.Services.AddService(this);

            textView.LineTransformers.Add(new SelectionColorizer(this));
            textView.InsertLayer(new SelectionLayer(this), KnownLayer.Selection, LayerInsertionPosition.Replace);

            Caret = new Caret(this);
            Caret.PositionChanged += (sender, e) => RequestSelectionValidation();
            Caret.PositionChanged += CaretPositionChanged;
            AttachTypingEvents();

            LeftMargins.CollectionChanged += LeftMargins_CollectionChanged;

            DefaultInputHandler = new TextAreaDefaultInputHandler(this);
            ActiveInputHandler  = DefaultInputHandler;
        }
Exemple #4
0
 private static void AddBinding(RoutedCommand command, KeyModifiers modifiers, Key key,
                                EventHandler <ExecutedRoutedEventArgs> handler)
 {
     CommandBindings.Add(new RoutedCommandBinding(command, handler));
     KeyBindings.Add(TextAreaDefaultInputHandler.CreateKeyBinding(command, modifiers, key));
 }
 private static void AddBinding(RoutedCommand command, KeyGesture gesture, EventHandler <ExecutedRoutedEventArgs> handler)
 {
     AddBinding(command, handler);
     KeyBindings.Add(TextAreaDefaultInputHandler.CreateKeyBinding(command, gesture));
 }