@@ -72,6 +72,8 @@ public LineNumberMargin(bool usePresenter, bool isOld)
72
72
{
73
73
_usePresenter = usePresenter ;
74
74
_isOld = isOld ;
75
+
76
+ Margin = new Thickness ( 8 , 0 ) ;
75
77
ClipToBounds = true ;
76
78
}
77
79
@@ -105,11 +107,80 @@ public override void Render(DrawingContext context)
105
107
continue ;
106
108
107
109
var y = line . GetTextLineVisualYPosition ( line . TextLines [ 0 ] , VisualYPosition . LineMiddle ) - view . VerticalOffset ;
110
+ var txt = new FormattedText (
111
+ lineNumber ,
112
+ CultureInfo . CurrentCulture ,
113
+ FlowDirection . LeftToRight ,
114
+ typeface ,
115
+ presenter . FontSize ,
116
+ presenter . Foreground ) ;
117
+ context . DrawText ( txt , new Point ( Bounds . Width - txt . Width , y - txt . Height * 0.5 ) ) ;
118
+ }
119
+ }
120
+ }
121
+
122
+ protected override Size MeasureOverride ( Size availableSize )
123
+ {
124
+ var presenter = this . FindAncestorOfType < ThemedTextDiffPresenter > ( ) ;
125
+ if ( presenter == null )
126
+ return new Size ( 32 , 0 ) ;
127
+
128
+ var maxLineNumber = presenter . GetMaxLineNumber ( ) ;
129
+ var typeface = TextView . CreateTypeface ( ) ;
130
+ var test = new FormattedText (
131
+ $ "{ maxLineNumber } ",
132
+ CultureInfo . CurrentCulture ,
133
+ FlowDirection . LeftToRight ,
134
+ typeface ,
135
+ presenter . FontSize ,
136
+ Brushes . White ) ;
137
+ return new Size ( test . Width , 0 ) ;
138
+ }
139
+
140
+ protected override void OnDataContextChanged ( EventArgs e )
141
+ {
142
+ base . OnDataContextChanged ( e ) ;
143
+ InvalidateMeasure ( ) ;
144
+ }
108
145
109
- var prefix = null as FormattedText ;
146
+ private bool _usePresenter = false ;
147
+ private bool _isOld = false ;
148
+ }
149
+
150
+ public class LineModifyTypeMargin : AbstractMargin
151
+ {
152
+ public LineModifyTypeMargin ( )
153
+ {
154
+ Margin = new Thickness ( 1 , 0 ) ;
155
+ ClipToBounds = true ;
156
+ }
157
+
158
+ public override void Render ( DrawingContext context )
159
+ {
160
+ var presenter = this . FindAncestorOfType < ThemedTextDiffPresenter > ( ) ;
161
+ if ( presenter == null )
162
+ return ;
163
+
164
+ var lines = presenter . GetLines ( ) ;
165
+ var view = TextView ;
166
+ if ( view != null && view . VisualLinesValid )
167
+ {
168
+ var typeface = view . CreateTypeface ( ) ;
169
+ foreach ( var line in view . VisualLines )
170
+ {
171
+ if ( line . IsDisposed || line . FirstDocumentLine == null || line . FirstDocumentLine . IsDeleted )
172
+ continue ;
173
+
174
+ var index = line . FirstDocumentLine . LineNumber ;
175
+ if ( index > lines . Count )
176
+ break ;
177
+
178
+ var info = lines [ index - 1 ] ;
179
+ var y = line . GetTextLineVisualYPosition ( line . TextLines [ 0 ] , VisualYPosition . LineMiddle ) - view . VerticalOffset ;
180
+ var indicator = null as FormattedText ;
110
181
if ( info . Type == Models . TextDiffLineType . Added )
111
182
{
112
- prefix = new FormattedText (
183
+ indicator = new FormattedText (
113
184
"+" ,
114
185
CultureInfo . CurrentCulture ,
115
186
FlowDirection . LeftToRight ,
@@ -119,7 +190,7 @@ public override void Render(DrawingContext context)
119
190
}
120
191
else if ( info . Type == Models . TextDiffLineType . Deleted )
121
192
{
122
- prefix = new FormattedText (
193
+ indicator = new FormattedText (
123
194
"-" ,
124
195
CultureInfo . CurrentCulture ,
125
196
FlowDirection . LeftToRight ,
@@ -128,17 +199,8 @@ public override void Render(DrawingContext context)
128
199
Brushes . Red ) ;
129
200
}
130
201
131
- if ( prefix != null )
132
- context . DrawText ( prefix , new Point ( 0 , y - prefix . Height * 0.5 ) ) ;
133
-
134
- var txt = new FormattedText (
135
- lineNumber ,
136
- CultureInfo . CurrentCulture ,
137
- FlowDirection . LeftToRight ,
138
- typeface ,
139
- presenter . FontSize ,
140
- presenter . Foreground ) ;
141
- context . DrawText ( txt , new Point ( Bounds . Width - txt . Width , y - txt . Height * 0.5 ) ) ;
202
+ if ( indicator != null )
203
+ context . DrawText ( indicator , new Point ( 0 , y - indicator . Height * 0.5 ) ) ;
142
204
}
143
205
}
144
206
}
@@ -147,12 +209,12 @@ protected override Size MeasureOverride(Size availableSize)
147
209
{
148
210
var presenter = this . FindAncestorOfType < ThemedTextDiffPresenter > ( ) ;
149
211
if ( presenter == null )
150
- return new Size ( 32 , 0 ) ;
212
+ return new Size ( 0 , 0 ) ;
151
213
152
214
var maxLineNumber = presenter . GetMaxLineNumber ( ) ;
153
215
var typeface = TextView . CreateTypeface ( ) ;
154
216
var test = new FormattedText (
155
- $ "- { maxLineNumber } ",
217
+ $ "-",
156
218
CultureInfo . CurrentCulture ,
157
219
FlowDirection . LeftToRight ,
158
220
typeface ,
@@ -166,9 +228,6 @@ protected override void OnDataContextChanged(EventArgs e)
166
228
base . OnDataContextChanged ( e ) ;
167
229
InvalidateMeasure ( ) ;
168
230
}
169
-
170
- private bool _usePresenter = false ;
171
- private bool _isOld = false ;
172
231
}
173
232
174
233
public class LineBackgroundRenderer : IBackgroundRenderer
@@ -700,10 +759,11 @@ public class CombinedTextDiffPresenter : ThemedTextDiffPresenter
700
759
{
701
760
public CombinedTextDiffPresenter ( ) : base ( new TextArea ( ) , new TextDocument ( ) )
702
761
{
703
- TextArea . LeftMargins . Add ( new LineNumberMargin ( false , true ) { Margin = new Thickness ( 8 , 0 ) } ) ;
762
+ TextArea . LeftMargins . Add ( new LineNumberMargin ( false , true ) ) ;
704
763
TextArea . LeftMargins . Add ( new VerticalSeperatorMargin ( ) ) ;
705
- TextArea . LeftMargins . Add ( new LineNumberMargin ( false , false ) { Margin = new Thickness ( 8 , 0 ) } ) ;
764
+ TextArea . LeftMargins . Add ( new LineNumberMargin ( false , false ) ) ;
706
765
TextArea . LeftMargins . Add ( new VerticalSeperatorMargin ( ) ) ;
766
+ TextArea . LeftMargins . Add ( new LineModifyTypeMargin ( ) ) ;
707
767
}
708
768
709
769
public override List < Models . TextDiffLine > GetLines ( )
@@ -904,8 +964,9 @@ public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
904
964
{
905
965
public SingleSideTextDiffPresenter ( ) : base ( new TextArea ( ) , new TextDocument ( ) )
906
966
{
907
- TextArea . LeftMargins . Add ( new LineNumberMargin ( true , false ) { Margin = new Thickness ( 8 , 0 ) } ) ;
967
+ TextArea . LeftMargins . Add ( new LineNumberMargin ( true , false ) ) ;
908
968
TextArea . LeftMargins . Add ( new VerticalSeperatorMargin ( ) ) ;
969
+ TextArea . LeftMargins . Add ( new LineModifyTypeMargin ( ) ) ;
909
970
}
910
971
911
972
public override List < Models . TextDiffLine > GetLines ( )
0 commit comments