如何更改Visual Studio 2017中的CTRL C以复制单词,而不是整个行



这个问题类似于在Visual Studio中禁用单行副本,只是我想将其更改以复制光标已打开的单词,如果没有选择。如果它在空白空间,我不在乎,请复制这条线,但是99%我正在尝试复制一个单词,而不是这行?

要复制出现的单词,您可以将快捷方式分配给以下Visual Commander(由me开发(命令(语言C#(:

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        this.DTE = DTE;
        EnvDTE.TextSelection ts = TryGetFocusedDocumentSelection();
        if (ts != null && ts.IsEmpty)
            CopyWord(ts);
        else if (IsCommandAvailable("Edit.Copy"))
            DTE.ExecuteCommand("Edit.Copy");
    }
    private void CopyWord(EnvDTE.TextSelection ts)
    {
        EnvDTE.EditPoint left = ts.ActivePoint.CreateEditPoint();
        left.WordLeft();
        EnvDTE.EditPoint right = ts.ActivePoint.CreateEditPoint();
        right.WordRight();
        System.Windows.Clipboard.SetText(left.GetText(right));
    }
    private EnvDTE.TextSelection TryGetFocusedDocumentSelection()
    {
        try
        {
            return DTE.ActiveWindow.Document.Selection as EnvDTE.TextSelection;
        }
        catch(System.Exception)
        {
        }
        return null;
    }
    private bool IsCommandAvailable(string commandName)
    {
        EnvDTE80.Commands2 commands = DTE.Commands as EnvDTE80.Commands2;
        if (commands == null)
            return false;
        EnvDTE.Command command = commands.Item(commandName, 0);
        if (command == null)
            return false;
        return command.IsAvailable;
    }
    private EnvDTE80.DTE2 DTE;
}

最新更新