From 785d14945c18215cc2720ce23cd2aa2e79c26edc Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Sun, 21 Sep 2025 21:54:40 +0800 Subject: [PATCH] =?UTF-8?q?Guard=20selection=20logic=20to=20avoid=20Argume?= =?UTF-8?q?ntOutOfRangeException=20when=20base=20name=20isn=E2=80=99t=20fo?= =?UTF-8?q?und?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../Views/RenameFile.xaml.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/RenameFile.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/RenameFile.xaml.cs index 23bdfd92a..d0a2efc22 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/RenameFile.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/RenameFile.xaml.cs @@ -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); } }