diff --git a/src/AvaloniaEdit/CodeCompletion/CompletionList.cs b/src/AvaloniaEdit/CodeCompletion/CompletionList.cs index 53ba1e4..e45e4cc 100644 --- a/src/AvaloniaEdit/CodeCompletion/CompletionList.cs +++ b/src/AvaloniaEdit/CodeCompletion/CompletionList.cs @@ -38,6 +38,12 @@ namespace AvaloniaEdit.CodeCompletion public CompletionList() { DoubleTapped += OnDoubleTapped; + + CompletionAcceptKeys = new[] + { + Key.Enter, + Key.Tab, + }; } @@ -103,6 +109,11 @@ namespace AvaloniaEdit.CodeCompletion } } + /// + /// Gets or sets the array of keys that are supposed to request insertation of the completion + /// + public Key[] CompletionAcceptKeys { get; set; } + /// /// Gets the scroll viewer used in this list box. /// @@ -163,13 +174,13 @@ namespace AvaloniaEdit.CodeCompletion e.Handled = true; _listBox.SelectIndex(_listBox.ItemCount - 1); break; - case Key.Tab: - case Key.Enter: - if(CurrentList.Count > 0) + default: + if (CompletionAcceptKeys.Contains(e.Key) && CurrentList.Count > 0) { e.Handled = true; RequestInsertion(e); - } + } + break; } } diff --git a/src/AvaloniaEdit/Editing/TextArea.cs b/src/AvaloniaEdit/Editing/TextArea.cs index 101986b..4414f39 100644 --- a/src/AvaloniaEdit/Editing/TextArea.cs +++ b/src/AvaloniaEdit/Editing/TextArea.cs @@ -1192,7 +1192,12 @@ namespace AvaloniaEdit.Editing public override TextSelection Selection { - get => new TextSelection(_textArea.Caret.Position.Column, _textArea.Caret.Position.Column + _textArea.Selection.Length); + get + { + if (_textArea == null) + return new TextSelection(0, 0); + return new TextSelection(_textArea.Caret.Position.Column, _textArea.Caret.Position.Column + _textArea.Selection.Length); + } set { var selection = _textArea.Selection;