Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customisation of the keys that trigger insertation of a completion #358

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/AvaloniaEdit/CodeCompletion/CompletionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public class CompletionList : TemplatedControl
public CompletionList()
{
DoubleTapped += OnDoubleTapped;

CompletionAcceptKeys = new[]
{
Key.Enter,
Key.Tab,
};
}


Expand Down Expand Up @@ -103,6 +109,11 @@ public CompletionListBox ListBox
}
}

/// <summary>
/// Gets or sets the array of keys that are supposed to request insertation of the completion
/// </summary>
public Key[] CompletionAcceptKeys { get; set; }

/// <summary>
/// Gets the scroll viewer used in this list box.
/// </summary>
Expand Down Expand Up @@ -163,13 +174,13 @@ public void HandleKey(KeyEventArgs e)
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;
}
}
Expand Down