我正在开发一个项目,我需要创建自定义编辑器并为自定义代码文件使用投影缓冲区,我已经按照本文 https://joshvarty.wordpress.com/中的步骤创建了一个代码窗口2014/08/01/翻录-视觉-工作室-编辑器-分开-与-投影-缓冲区/
但是,我无法让代码窗口响应任何键输入,尽管使用拖放工作
该扩展是为 Visual Studio 2015 编写的,是否需要注意它们的任何额外步骤才能使代码窗口正常工作?
这是我正在使用的代码:
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;
}