-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathHelpers.cs
36 lines (32 loc) · 1.26 KB
/
Helpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.ComponentModelHost;
namespace ChrisLajoie.DupSelection
{
static class Helpers
{
public static IWpfTextView GetCurentTextView()
{
var componentModel = GetComponentModel();
if (componentModel == null) return null;
var vsTextView = GetCurrentNativeTextView();
if (vsTextView == null) return null;
var editorAdapter = componentModel.GetService<IVsEditorAdaptersFactoryService>();
return editorAdapter.GetWpfTextView(vsTextView);
}
public static IVsTextView GetCurrentNativeTextView()
{
var textManager = (IVsTextManager)ServiceProvider.GlobalProvider.GetService(typeof(SVsTextManager));
IVsTextView activeView = null;
textManager.GetActiveView(1, null, out activeView);
return activeView;
}
public static IComponentModel GetComponentModel()
{
return (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
}
}
}