Support for CloseKey in autocomplete append

This commit is contained in:
Thomas
2023-03-31 20:25:46 +01:00
parent dbe78d5556
commit 1eb6db9538
2 changed files with 67 additions and 2 deletions

View File

@@ -16,11 +16,10 @@ namespace Terminal.Gui.ViewTests {
}
[Fact, AutoInitShutdown]
public void TestAutocomplete_ShowThenAccept_MatchCase()
public void TestAutoAppend_ShowThenAccept_MatchCase()
{
var tf = GetTextFieldsInView();
tf.Autocomplete = new AppendAutocomplete(tf);
var generator = (SingleWordSuggestionGenerator)tf.Autocomplete.SuggestionGenerator;
generator.AllSuggestions = new List<string>{"fish"};
@@ -49,6 +48,52 @@ namespace Terminal.Gui.ViewTests {
Assert.NotSame(tf,Application.Top.Focused);
}
[Fact, AutoInitShutdown]
public void TestAutoAppend_AfterCloseKey_NoAutocomplete()
{
var tf = GetTextFieldsInViewSuggestingFish();
// f is typed and suggestion is "fish"
tf.Redraw(tf.Bounds);
TestHelpers.AssertDriverContentsAre("fish",output);
Assert.Equal("f",tf.Text.ToString());
// When cancelling autocomplete
Application.Driver.SendKeys('e',ConsoleKey.Escape,false,false,false);
// Suggestion should disapear
tf.Redraw(tf.Bounds);
TestHelpers.AssertDriverContentsAre("f",output);
Assert.Equal("f",tf.Text.ToString());
// Still has focus though
Assert.Same(tf,Application.Top.Focused);
// But can tab away
Application.Driver.SendKeys('\t',ConsoleKey.Tab,false,false,false);
Assert.NotSame(tf,Application.Top.Focused);
}
private TextField GetTextFieldsInViewSuggestingFish ()
{
var tf = GetTextFieldsInView();
tf.Autocomplete = new AppendAutocomplete(tf);
var generator = (SingleWordSuggestionGenerator)tf.Autocomplete.SuggestionGenerator;
generator.AllSuggestions = new List<string>{"fish"};
tf.Redraw(tf.Bounds);
TestHelpers.AssertDriverContentsAre("",output);
tf.ProcessKey(new KeyEvent(Key.f,new KeyModifiers()));
tf.Redraw(tf.Bounds);
TestHelpers.AssertDriverContentsAre("fish",output);
Assert.Equal("f",tf.Text.ToString());
return tf;
}
private TextField GetTextFieldsInView ()
{
var tf = new TextField{