From 21090e9d0d4d6775ecdcc1711e687772326ab2f1 Mon Sep 17 00:00:00 2001 From: Robert van der Hulst Date: Thu, 13 Feb 2025 12:30:33 +0100 Subject: [PATCH] Add overload for InterceptAsync with a command name, because some commands (such as Edit.ToggleLineComment) have no constants in the VS SDK files. --- .../Commands/Commands.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/Commands.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/Commands.cs index b7241b4..8e53368 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/Commands.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/Commands.cs @@ -125,6 +125,19 @@ public async Task InterceptAsync(CommandID cmd, Func priority.UnregisterPriorityCommandTarget(cookie)); } + /// + /// Intercept any command before it is being handled by other command handlers. + /// + /// Returns an that will remove the command interceptor when disposed. + public async Task InterceptAsync(string name, Func func) + { + CommandID? cmd = await FindCommandAsync(name); + if (cmd == null) + { + throw new ArgumentException($"Command '{name}' not found."); + } + return await InterceptAsync(cmd, func); + } } internal class CommandInterceptor : IOleCommandTarget