4
4
using System . Text ;
5
5
using System . Windows ;
6
6
using System . Windows . Controls ;
7
- using MadsKristensen . EditorExtensions . Margin ;
8
7
using MadsKristensen . EditorExtensions . Settings ;
9
8
using Microsoft . VisualStudio . Text ;
10
- using Microsoft . VisualStudio . Text . Editor ;
11
9
using mshtml ;
12
10
13
11
namespace MadsKristensen . EditorExtensions . Markdown
@@ -17,9 +15,9 @@ internal class MarkdownMargin : CompilingMarginBase
17
15
private HTMLDocument _document ;
18
16
private WebBrowser _browser ;
19
17
private const string _stylesheet = "WE-Markdown.css" ;
20
- private float _cachedPosition = 0 ,
21
- _cachedHeight = 0 ,
22
- _positionPercentage = 0 ;
18
+ private double _cachedPosition = 0 ,
19
+ _cachedHeight = 0 ,
20
+ _positionPercentage = 0 ;
23
21
24
22
public MarkdownMargin ( ITextDocument document )
25
23
: base ( WESettings . Instance . Markdown , document )
@@ -76,7 +74,7 @@ protected override void UpdateMargin(CompilerResult result)
76
74
}
77
75
78
76
_cachedPosition = _document . documentElement . getAttribute ( "scrollTop" ) ;
79
- _cachedHeight = _document . body . offsetHeight ;
77
+ _cachedHeight = Math . Max ( 1.0 , _document . body . offsetHeight ) ;
80
78
_positionPercentage = _cachedPosition * 100 / _cachedHeight ;
81
79
82
80
_browser . NavigateToString ( html ) ;
@@ -89,7 +87,6 @@ protected override FrameworkElement CreatePreviewControl()
89
87
_browser . Navigated += ( s , e ) =>
90
88
{
91
89
_document = _browser . Document as HTMLDocument ;
92
- _cachedPosition = _document . documentElement . getAttribute ( "scrollTop" ) ;
93
90
_cachedHeight = _document . body . offsetHeight ;
94
91
_document . documentElement . setAttribute ( "scrollTop" , _positionPercentage * _cachedHeight / 100 ) ;
95
92
} ;
0 commit comments