Skip to content

Commit

Permalink
Merge pull request #358 from zenonet/master
Browse files Browse the repository at this point in the history
Allow customisation of the keys that trigger insertation of a completion
  • Loading branch information
danipen authored Jul 19, 2023
2 parents e9cb45e + 7102287 commit d091742
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit d091742

Please sign in to comment.