Skip to content

Commit 92c84a9

Browse files
committed
feat: Add setting to clear search on execution
1 parent 9cf4b1c commit 92c84a9

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

WorkspaceLauncherForVSCode/Classes/SettingsManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ public class SettingsManager : JsonSettingsManager
139139
"Automatically refreshes the workspace list when changes are detected in Visual Studio / Code's recent list.",
140140
true);
141141

142+
private readonly ToggleSetting _clearSearchOnExecute = new(
143+
Namespaced(nameof(ClearSearchOnExecute)),
144+
"Clear search text after executing open Visual Studio / Code command",
145+
"If checked, the search text will be cleared after the open Visual Studio / Code command is executed.",
146+
false);
147+
142148
private readonly ChoiceSetSetting _searchBy = new(
143149
Namespaced(nameof(SearchBy)),
144150
"Search By",
@@ -202,6 +208,7 @@ public SortBy SortBy
202208
public bool EnableLogging => _enableLogging.Value;
203209
public bool EnableVisualStudio => _enableVisualStudio.Value;
204210
public bool EnableWorkspaceWatcher => _enableWorkspaceWatcher.Value;
211+
public bool ClearSearchOnExecute => _clearSearchOnExecute.Value;
205212

206213
public TagType TagTypes
207214
{
@@ -310,6 +317,7 @@ public SettingsManager()
310317
Settings.Add(_terminalType);
311318
Settings.Add(_vsSecondaryCommand);
312319
Settings.Add(_vscodeSecondaryCommand);
320+
Settings.Add(_clearSearchOnExecute);
313321
// Settings.Add(_enableWorkspaceWatcher);
314322
#if DEBUG
315323
Settings.Add(_enableLogging);

WorkspaceLauncherForVSCode/Commands/OpenSolutionCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public override CommandResult Invoke()
7979
if (solutionPath == Workspace.WindowsPath)
8080
{
8181
window.SwitchToWindow();
82-
return CommandResult.Dismiss();
82+
return PageCommandResultHandler.HandleCommandResult(page);
8383
}
8484
}
8585
}
@@ -97,6 +97,6 @@ public override CommandResult Invoke()
9797
OpenInShellHelper.OpenInShell(Workspace.VSInstance.InstancePath, Workspace.Path, runAs: _elevated ? OpenInShellHelper.ShellRunAsType.Administrator : OpenInShellHelper.ShellRunAsType.None);
9898
}
9999

100-
return CommandResult.Dismiss();
100+
return PageCommandResultHandler.HandleCommandResult(page);
101101
}
102102
}

WorkspaceLauncherForVSCode/Commands/OpenVisualStudioCodeCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ public override CommandResult Invoke()
8282

8383
Task.Run(() => page.UpdateFrequencyAsync(Workspace.Path));
8484

85-
return CommandResult.Dismiss();
85+
return PageCommandResultHandler.HandleCommandResult(page);
8686
}
8787
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Modifications copyright (c) 2025 tanchekwei
2+
// Licensed under the MIT License. See the LICENSE file in the project root for details.
3+
using Microsoft.CommandPalette.Extensions.Toolkit;
4+
5+
namespace WorkspaceLauncherForVSCode.Commands;
6+
7+
public static class PageCommandResultHandler
8+
{
9+
public static CommandResult HandleCommandResult(VisualStudioCodePage? page)
10+
{
11+
if (page != null && page.SettingsManager.ClearSearchOnExecute)
12+
{
13+
// reset search text
14+
if (!string.IsNullOrEmpty(page.SearchText))
15+
{
16+
page.UpdateSearchText(page.SearchText, "");
17+
page.SearchText = "";
18+
}
19+
}
20+
21+
return CommandResult.Dismiss();
22+
}
23+
}

WorkspaceLauncherForVSCode/Pages/VisualStudioCodePage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public sealed partial class VisualStudioCodePage : DynamicListPage, IDisposable
3131
private readonly IPinService _pinService;
3232

3333
public List<VisualStudioCodeWorkspace> AllWorkspaces { get; } = new();
34+
public SettingsManager SettingsManager { get; } = new();
3435
private readonly List<ListItem> _visibleItems = new();
3536
private List<VisualStudioCodeWorkspace> _cachedFilteredWorkspaces = new();
3637

@@ -67,6 +68,7 @@ IPinService pinService
6768
Id = "VisualStudioCodePage";
6869

6970
_settingsManager = settingsManager;
71+
SettingsManager = _settingsManager;
7072
_vscodeService = vscodeService;
7173
_workspaceStorage = workspaceStorage;
7274
_countTracker = countTracker;

0 commit comments

Comments
 (0)