1717// DEALINGS IN THE SOFTWARE.
1818
1919using System ;
20+ using System . Globalization ;
2021using Avalonia ;
2122using Avalonia . Controls ;
2223using Avalonia . Media ;
@@ -90,7 +91,44 @@ private void StopBlinkAnimation()
9091 public override void Render ( DrawingContext drawingContext )
9192 {
9293 base . Render ( drawingContext ) ;
93-
94+
95+ var caretRect = _caretRectangle ;
96+
97+ if ( ! string . IsNullOrEmpty ( _textArea . PreeditText ) )
98+ {
99+ var caretPos = new Point (
100+ caretRect . X - TextView . HorizontalOffset ,
101+ caretRect . Y - TextView . VerticalOffset
102+ ) ;
103+
104+ var formattedText = new FormattedText (
105+ _textArea . PreeditText ,
106+ CultureInfo . CurrentCulture ,
107+ _textArea . FlowDirection ,
108+ new Typeface ( _textArea . FontFamily , _textArea . FontStyle , _textArea . FontWeight ,
109+ _textArea . FontStretch ) ,
110+ _textArea . FontSize ,
111+ Brushes . Black
112+ ) ;
113+
114+ var textBounds = new Rect (
115+ caretPos . X ,
116+ caretPos . Y ,
117+ formattedText . Width ,
118+ formattedText . Height
119+ ) ;
120+ drawingContext . FillRectangle ( Brushes . White , textBounds ) ;
121+
122+ drawingContext . DrawText ( formattedText , caretPos ) ;
123+
124+ caretRect = new Rect (
125+ caretRect . X + formattedText . Width ,
126+ caretRect . Y ,
127+ caretRect . Width ,
128+ caretRect . Height
129+ ) ;
130+ }
131+
94132 if ( _isVisible && _blink )
95133 {
96134 var caretBrush = CaretBrush ?? TextView . GetValue ( TextBlock . ForegroundProperty ) ;
@@ -105,13 +143,14 @@ public override void Render(DrawingContext drawingContext)
105143 }
106144 }
107145
108- var r = new Rect ( _caretRectangle . X - TextView . HorizontalOffset ,
109- _caretRectangle . Y - TextView . VerticalOffset ,
110- _caretRectangle . Width ,
111- _caretRectangle . Height ) ;
146+ var r = new Rect ( caretRect . X - TextView . HorizontalOffset ,
147+ caretRect . Y - TextView . VerticalOffset ,
148+ caretRect . Width ,
149+ caretRect . Height ) ;
112150
113- drawingContext . FillRectangle ( caretBrush , PixelSnapHelpers . Round ( r , PixelSnapHelpers . GetPixelSize ( this ) ) ) ;
151+ drawingContext . FillRectangle ( caretBrush ,
152+ PixelSnapHelpers . Round ( r , PixelSnapHelpers . GetPixelSize ( this ) ) ) ;
114153 }
115154 }
116155 }
117- }
156+ }
0 commit comments