这个问题类似于Disabling single line copy in Visual Studio ,除了我想将其更改为仅复制光标所在的单词(如果未选择任何内容)。如果它在空白处,当然,我不在乎,复制该行,但 99% 我试图复制一个单词,而不是该行这可能吗?
最佳答案
要复制插入符号所在的单词,您可以为以下 Visual Commander 分配快捷方式(由我开发)命令(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;
}
关于visual-studio - 如何在 Visual Studio 2017 中更改 Ctrl+C 以复制 Word,而不是整行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55942005/