Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 9085873

Browse files
authored
Merge pull request #61 from madskristensen/master
Load image async
2 parents cbedf66 + a8831ca commit 9085873

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

GlyphfriendPackage.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
using Microsoft.VisualStudio.Shell;
2-
using Microsoft.VisualStudio.Shell.Interop;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.IO;
64
using System.Windows.Media;
75
using System.Windows.Media.Imaging;
86

97
namespace Glyphfriend
108
{
11-
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
12-
public sealed class GlyphfriendPackage : Package
9+
public sealed class GlyphfriendPackage
1310
{
1411
private static Dictionary<string, Dictionary<string,ImageSource>> _glyphs;
1512
internal static Dictionary<string, Dictionary<string, ImageSource>> Glyphs

Helpers/HtmlTextViewListener.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System;
2-
using System.ComponentModel.Composition;
1+
using System.ComponentModel.Composition;
32
using Microsoft.VisualStudio.Editor;
3+
using Microsoft.VisualStudio.Text.Editor;
44
using Microsoft.VisualStudio.TextManager.Interop;
55
using Microsoft.VisualStudio.Utilities;
6-
using Microsoft.VisualStudio.Text.Editor;
76

87
namespace Glyphfriend.Helpers
98
{
@@ -16,9 +15,12 @@ class HtmlTextViewListener : IVsTextViewCreationListener
1615
public void VsTextViewCreated(IVsTextView textViewAdapter)
1716
{
1817
// If the Glyphs haven't been loaded, load them
19-
if(GlyphfriendPackage.Glyphs == null)
18+
if (GlyphfriendPackage.Glyphs == null)
2019
{
21-
GlyphfriendPackage.LoadGlyphs();
20+
System.Threading.Tasks.Task.Run(() =>
21+
{
22+
GlyphfriendPackage.LoadGlyphs();
23+
});
2224
}
2325
}
2426
}

Helpers/MarkdownTextViewListener.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using System.Runtime.InteropServices;
4+
using Microsoft.VisualStudio;
35
using Microsoft.VisualStudio.Editor;
46
using Microsoft.VisualStudio.Language.Intellisense;
57
using Microsoft.VisualStudio.OLE.Interop;
68
using Microsoft.VisualStudio.Text;
79
using Microsoft.VisualStudio.Text.Editor;
810
using Microsoft.VisualStudio.TextManager.Interop;
911
using Microsoft.VisualStudio.Utilities;
10-
using Microsoft.VisualStudio;
11-
using System.Runtime.InteropServices;
1212

1313
namespace Glyphfriend.Helpers
1414
{
@@ -28,7 +28,10 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
2828
// If the Emojis haven't been loaded, load them
2929
if (GlyphfriendPackage.Emojis == null)
3030
{
31-
GlyphfriendPackage.LoadEmojis();
31+
System.Threading.Tasks.Task.Run(() =>
32+
{
33+
GlyphfriendPackage.LoadEmojis();
34+
});
3235
}
3336

3437
// Set up the Completion handler for Markdown documents
@@ -91,7 +94,7 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv
9194
hresult = Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
9295
}
9396

94-
// After the pre-processing has been performed, evaluate the current state
97+
// After the pre-processing has been performed, evaluate the current state
9598
// and session
9699
if (ErrorHandler.Succeeded(hresult))
97100
{
@@ -153,6 +156,13 @@ private bool Start()
153156
SnapshotPoint caret = _textView.Caret.Position.BufferPosition;
154157
ITextSnapshot snapshot = caret.Snapshot;
155158

159+
if (caret > 1)
160+
{
161+
char prev = snapshot.GetText(caret - 2, 1)[0];
162+
if (!char.IsWhiteSpace(prev))
163+
return false;
164+
}
165+
156166
// Generate a session based off of the existing broker and textview
157167
if (!_broker.IsCompletionActive(_textView))
158168
{
@@ -177,7 +187,7 @@ private bool Complete(bool force)
177187
{
178188
return false;
179189
}
180-
190+
181191
// Based off of the available selection, determine if it should be dismissed (via Dismiss) or
182192
// output (via Commit)
183193
if (!_currentSession.SelectedCompletionSet.SelectionStatus.IsSelected && !force)
@@ -213,7 +223,7 @@ private bool Cancel()
213223
{
214224
return false;
215225
}
216-
226+
217227
// Explicitly cancel the current session
218228
_currentSession.Dismiss();
219229

@@ -223,7 +233,7 @@ private bool Cancel()
223233
private bool DoesSessionExist
224234
{
225235
// Ensures that the current session exists
226-
get { return _currentSession != null; }
236+
get { return _currentSession != null; }
227237
}
228238

229239
private static char GetTypeChar(IntPtr pvaIn)

0 commit comments

Comments
 (0)