mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Guard selection logic to avoid ArgumentOutOfRangeException when base name isn’t found
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
0b7c0408f8
commit
785d14945c
1 changed files with 10 additions and 3 deletions
|
|
@ -55,13 +55,20 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
if (sender is not TextBox textBox) return;
|
||||
if (_info is DirectoryInfo)
|
||||
{
|
||||
await Application.Current.Dispatcher.InvokeAsync(textBox.SelectAll, DispatcherPriority.Background);
|
||||
await textBox.Dispatcher.InvokeAsync(textBox.SelectAll, DispatcherPriority.Background);
|
||||
return;
|
||||
}
|
||||
// select everything but the extension
|
||||
else if (_info is FileInfo info)
|
||||
if (_info is FileInfo info)
|
||||
{
|
||||
string properName = Path.GetFileNameWithoutExtension(info.Name);
|
||||
Application.Current.Dispatcher.Invoke(textBox.Select, DispatcherPriority.Background, textBox.Text.IndexOf(properName), properName.Length);
|
||||
int start = textBox.Text.LastIndexOf(properName, StringComparison.OrdinalIgnoreCase);
|
||||
if (start < 0)
|
||||
{
|
||||
await textBox.Dispatcher.InvokeAsync(textBox.SelectAll, DispatcherPriority.Background);
|
||||
return;
|
||||
}
|
||||
await textBox.Dispatcher.InvokeAsync(() => textBox.Select(start, properName.Length), DispatcherPriority.Background);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue