Skip to content

Commit 060072e

Browse files
Merge pull request #832 from am11/markdown-bugfixes
Markdown: Preserve scrolling on compile (#830)
2 parents e9fbade + b4820e2 commit 060072e

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

EditorExtensions/Markdown/Margin/MarkdownMargin.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
using System.Windows.Controls;
77
using MadsKristensen.EditorExtensions.Settings;
88
using Microsoft.VisualStudio.Text;
9+
using mshtml;
910

1011
namespace MadsKristensen.EditorExtensions.Markdown
1112
{
1213
internal class MarkdownMargin : CompilingMarginBase
1314
{
15+
private HTMLDocument _document;
1416
private WebBrowser _browser;
1517
private const string _stylesheet = "WE-Markdown.css";
18+
private double _cachedPosition = 0,
19+
_cachedHeight = 0,
20+
_positionPercentage = 0;
1621

1722
public MarkdownMargin(ITextDocument document)
1823
: base(WESettings.Instance.Markdown, document)
1924
{ }
2025

21-
2226
public static string GetStylesheet()
2327
{
2428
string file = GetCustomStylesheetFilePath();
@@ -62,13 +66,31 @@ protected override void UpdateMargin(CompilerResult result)
6266
</head>
6367
<body>{1}</body></html>", GetStylesheet(), result.Result);
6468

69+
if (_document == null)
70+
{
71+
_browser.NavigateToString(html);
72+
73+
return;
74+
}
75+
76+
_cachedPosition = _document.documentElement.getAttribute("scrollTop");
77+
_cachedHeight = Math.Max(1.0, _document.body.offsetHeight);
78+
_positionPercentage = _cachedPosition * 100 / _cachedHeight;
79+
6580
_browser.NavigateToString(html);
6681
}
6782

6883
protected override FrameworkElement CreatePreviewControl()
6984
{
7085
_browser = new WebBrowser();
7186
_browser.HorizontalAlignment = HorizontalAlignment.Stretch;
87+
_browser.Navigated += (s, e) =>
88+
{
89+
_document = _browser.Document as HTMLDocument;
90+
_cachedHeight = _document.body.offsetHeight;
91+
_document.documentElement.setAttribute("scrollTop", _positionPercentage * _cachedHeight / 100);
92+
};
93+
7294
return _browser;
7395
}
7496
}

EditorExtensions/TypeScript/Compilers/TypeScriptCompilationNotifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ private string GetOutputFileName()
3333
Project project = ProjectHelpers.GetProject(SourceFilePath);
3434
IVsHierarchy hierarchy = null;
3535

36-
if (project != null)
37-
solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);
36+
if (project != null && solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy) != VSConstants.S_OK)
37+
return string.Empty;
3838

3939
IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;
4040

EditorExtensions/WebEssentials2013.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@
209209
</Reference>
210210
</ItemGroup>
211211
<ItemGroup>
212+
<COMReference Include="MSHTML">
213+
<Guid>{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}</Guid>
214+
<VersionMajor>4</VersionMajor>
215+
<VersionMinor>0</VersionMinor>
216+
<Lcid>0</Lcid>
217+
<WrapperTool>primary</WrapperTool>
218+
<Isolated>False</Isolated>
219+
<EmbedInteropTypes>True</EmbedInteropTypes>
220+
</COMReference>
212221
<COMReference Include="stdole">
213222
<Guid>{00020430-0000-0000-C000-000000000046}</Guid>
214223
<VersionMajor>2</VersionMajor>

0 commit comments

Comments
 (0)