mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Fix recommending parent folder
This commit is contained in:
@@ -430,7 +430,7 @@ namespace Terminal.Gui {
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void GenerateSuggestions (params string [] suggestions)
|
||||
internal void GenerateSuggestions (FileDialogState state, params string [] suggestions)
|
||||
{
|
||||
if (!CursorIsAtEnd()) {
|
||||
return;
|
||||
@@ -446,12 +446,19 @@ namespace Terminal.Gui {
|
||||
|
||||
var term = path.Substring (last + 1);
|
||||
|
||||
if(term.Equals(state?.Directory?.Name))
|
||||
{
|
||||
ClearSuggestions();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Be case insensitive on Windows
|
||||
var validSuggestions = suggestions
|
||||
.Where (s => s.StartsWith (term))
|
||||
.OrderBy (m => m.Length)
|
||||
.ToArray ();
|
||||
|
||||
|
||||
// nothing to suggest
|
||||
if (validSuggestions.Length == 0 || validSuggestions [0].Length == term.Length) {
|
||||
ClearSuggestions ();
|
||||
@@ -479,11 +486,9 @@ namespace Terminal.Gui {
|
||||
e => e.FileSystemInfo is DirectoryInfo d
|
||||
? d.Name + System.IO.Path.DirectorySeparatorChar
|
||||
: e.FileSystemInfo.Name)
|
||||
.ToList ();
|
||||
.ToArray ();
|
||||
|
||||
suggestions.Add(state.Directory.Name);
|
||||
|
||||
GenerateSuggestions (suggestions.ToArray());
|
||||
GenerateSuggestions (state, suggestions);
|
||||
}
|
||||
|
||||
internal void SetTextTo (FileSystemInfo fileSystemInfo)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Terminal.Gui.Core {
|
||||
|
||||
tb.Text = "c:/fish";
|
||||
tb.CursorPosition = tb.Text.Length;
|
||||
tb.GenerateSuggestions ("fish", "fishes");
|
||||
tb.GenerateSuggestions (null, "fish", "fishes");
|
||||
|
||||
// should not report success for autocompletion because we already have that exact
|
||||
// string
|
||||
@@ -48,7 +48,7 @@ namespace Terminal.Gui.Core {
|
||||
|
||||
tb.Text = @"c:/fi";
|
||||
tb.CursorPosition = tb.Text.Length;
|
||||
tb.GenerateSuggestions ("fish", "fishes");
|
||||
tb.GenerateSuggestions (null, "fish", "fishes");
|
||||
|
||||
Assert.True (tb.AcceptSelectionIfAny ());
|
||||
Assert.Equal (@"c:\fish", tb.Text);
|
||||
|
||||
Reference in New Issue
Block a user