From be64abf873846a06556faa64a71477bb16ef827b Mon Sep 17 00:00:00 2001
From: zenonet <78077158+zenonet@users.noreply.github.com>
Date: Tue, 18 Jul 2023 20:22:08 +0200
Subject: [PATCH 1/2] Added CompletionList.CompletionAcceptKeys, an array of
keys to accept a completion
---
.../CodeCompletion/CompletionList.cs | 26 ++++++++++++++-----
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/src/AvaloniaEdit/CodeCompletion/CompletionList.cs b/src/AvaloniaEdit/CodeCompletion/CompletionList.cs
index 53ba1e4d..7e10c46d 100644
--- a/src/AvaloniaEdit/CodeCompletion/CompletionList.cs
+++ b/src/AvaloniaEdit/CodeCompletion/CompletionList.cs
@@ -38,6 +38,12 @@ public class CompletionList : TemplatedControl
public CompletionList()
{
DoubleTapped += OnDoubleTapped;
+
+ CompletionAcceptKeys = new[]
+ {
+ Key.Enter,
+ Key.Tab,
+ };
}
@@ -103,6 +109,11 @@ public CompletionListBox ListBox
}
}
+ ///
+ /// 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,14 @@ public void HandleKey(KeyEventArgs e)
e.Handled = true;
_listBox.SelectIndex(_listBox.ItemCount - 1);
break;
- case Key.Tab:
- case Key.Enter:
- if(CurrentList.Count > 0)
- {
- e.Handled = true;
- RequestInsertion(e);
- }
+ default:
+ if (CompletionAcceptKeys.Contains(e.Key))
+ if (CurrentList.Count > 0)
+ {
+ e.Handled = true;
+ RequestInsertion(e);
+ }
+
break;
}
}
From a5a97e40238159f6c2c15bb8c86eb795c98ff67c Mon Sep 17 00:00:00 2001
From: zenonet <78077158+zenonet@users.noreply.github.com>
Date: Wed, 19 Jul 2023 14:46:47 +0200
Subject: [PATCH 2/2] Reduced nesting by merging two if statements
---
src/AvaloniaEdit/CodeCompletion/CompletionList.cs | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/AvaloniaEdit/CodeCompletion/CompletionList.cs b/src/AvaloniaEdit/CodeCompletion/CompletionList.cs
index 7e10c46d..e45e4cc1 100644
--- a/src/AvaloniaEdit/CodeCompletion/CompletionList.cs
+++ b/src/AvaloniaEdit/CodeCompletion/CompletionList.cs
@@ -175,12 +175,11 @@ public void HandleKey(KeyEventArgs e)
_listBox.SelectIndex(_listBox.ItemCount - 1);
break;
default:
- if (CompletionAcceptKeys.Contains(e.Key))
- if (CurrentList.Count > 0)
- {
- e.Handled = true;
- RequestInsertion(e);
- }
+ if (CompletionAcceptKeys.Contains(e.Key) && CurrentList.Count > 0)
+ {
+ e.Handled = true;
+ RequestInsertion(e);
+ }
break;
}