@@ -68,6 +68,15 @@ public string CommitMessage
6868 set => SetValue ( CommitMessageProperty , value ) ;
6969 }
7070
71+ public static readonly StyledProperty < string > PlaceholderProperty =
72+ AvaloniaProperty . Register < CommitMessageTextEditor , string > ( nameof ( Placeholder ) , string . Empty ) ;
73+
74+ public string Placeholder
75+ {
76+ get => GetValue ( PlaceholderProperty ) ;
77+ set => SetValue ( PlaceholderProperty , value ) ;
78+ }
79+
7180 public static readonly StyledProperty < int > SubjectLengthProperty =
7281 AvaloniaProperty . Register < CommitMessageTextEditor , int > ( nameof ( SubjectLength ) , 0 ) ;
7382
@@ -109,20 +118,25 @@ public override void Render(DrawingContext context)
109118 var w = Bounds . Width ;
110119 var pen = new Pen ( SubjectLineBrush ) { DashStyle = DashStyle . Dash } ;
111120
112- if ( SubjectLength == 0 || CommitMessage . Trim ( ) . Length == 0 )
121+ if ( SubjectLength == 0 )
113122 {
114- var placeholder = new FormattedText (
115- App . Text ( "CommitMessageTextBox.Placeholder" ) ,
116- CultureInfo . CurrentCulture ,
117- FlowDirection . LeftToRight ,
118- new Typeface ( FontFamily ) ,
119- FontSize ,
120- Brushes . Gray ) ;
121-
122- context . DrawText ( placeholder , new Point ( 4 , 2 ) ) ;
123-
124- var y = 6 + placeholder . Height ;
125- context . DrawLine ( pen , new Point ( 0 , y ) , new Point ( w , y ) ) ;
123+ var placeholder = Placeholder ;
124+ if ( ! string . IsNullOrEmpty ( placeholder ) )
125+ {
126+ var formatted = new FormattedText (
127+ Placeholder ,
128+ CultureInfo . CurrentCulture ,
129+ FlowDirection . LeftToRight ,
130+ new Typeface ( FontFamily ) ,
131+ FontSize ,
132+ Brushes . Gray ) ;
133+
134+ context . DrawText ( formatted , new Point ( 4 , 2 ) ) ;
135+
136+ var y = 6 + formatted . Height ;
137+ context . DrawLine ( pen , new Point ( 0 , y ) , new Point ( w , y ) ) ;
138+ }
139+
126140 return ;
127141 }
128142
@@ -209,6 +223,11 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
209223
210224 SetCurrentValue ( SubjectLengthProperty , subjectLen ) ;
211225 }
226+ else if ( change . Property == PlaceholderProperty && IsLoaded )
227+ {
228+ if ( string . IsNullOrWhiteSpace ( CommitMessage ) )
229+ InvalidateVisual ( ) ;
230+ }
212231 }
213232
214233 protected override void OnTextChanged ( EventArgs e )
0 commit comments