C# 让Visual Studio自定义编辑器响应键输入
我正在进行一个项目,需要创建自定义编辑器并为自定义代码文件使用投影缓冲区,我已经按照本文中的步骤创建了一个代码窗口 但是,我无法让代码窗口响应任何键输入,尽管使用拖放操作是有效的 该扩展是为visual studio 2015编写的,他们的代码窗口是否需要执行任何额外的步骤才能正常工作 这是我正在使用的代码:C# 让Visual Studio自定义编辑器响应键输入,c#,visual-studio,visual-studio-extensions,vssdk,C#,Visual Studio,Visual Studio Extensions,Vssdk,我正在进行一个项目,需要创建自定义编辑器并为自定义代码文件使用投影缓冲区,我已经按照本文中的步骤创建了一个代码窗口 但是,我无法让代码窗口响应任何键输入,尽管使用拖放操作是有效的 该扩展是为visual studio 2015编写的,他们的代码窗口是否需要执行任何额外的步骤才能正常工作 这是我正在使用的代码: public IWpfTextViewHost CreateEditor(string filePath, int start = 0, int end = 0, bool crea
public IWpfTextViewHost CreateEditor(string filePath, int start = 0, int end = 0, bool createProjectedEditor = false)
{
//IVsInvisibleEditors are in-memory represenations of typical Visual Studio editors.
//Language services, highlighting and error squiggles are hooked up to these editors
//for us once we convert them to WpfTextViews.
var invisibleEditor = GetInvisibleEditor(filePath);
var docDataPointer = IntPtr.Zero;
Guid guidIVsTextLines = typeof(IVsTextLines).GUID;
ErrorHandler.ThrowOnFailure(invisibleEditor.GetDocData(
fEnsureWritable: 1
, riid: ref guidIVsTextLines
, ppDocData: out docDataPointer));
IVsTextLines docData = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer);
//Create a code window adapter
var codeWindow = _editorAdapter.CreateVsCodeWindowAdapter(VisualStudioServices.OLEServiceProvider);
ErrorHandler.ThrowOnFailure(codeWindow.SetBuffer(docData));
//Get a text view for our editor which we will then use to get the WPF control for that editor.
IVsTextView textView;
ErrorHandler.ThrowOnFailure(codeWindow.GetPrimaryView(out textView));
_currentlyFocusedTextView = textView;
RegisterDocument(filePath);
var textViewHost = _editorAdapter.GetWpfTextViewHost(textView);
return textViewHost;
}