|
|
@@ -10,6 +10,7 @@ using Avalonia.Layout;
|
|
|
using Avalonia.Media.Immutable;
|
|
|
using Avalonia.Controls.Documents;
|
|
|
using Avalonia.Input.TextInput;
|
|
|
+using Avalonia.Data;
|
|
|
|
|
|
namespace Avalonia.Controls.Presenters
|
|
|
{
|
|
|
@@ -52,7 +53,7 @@ namespace Avalonia.Controls.Presenters
|
|
|
AvaloniaProperty.RegisterDirect<TextPresenter, string?>(
|
|
|
nameof(Text),
|
|
|
o => o.Text,
|
|
|
- (o, v) => o.Text = v);
|
|
|
+ (o, v) => o.Text = v, defaultBindingMode: BindingMode.OneWay);
|
|
|
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="PreeditText"/> property.
|
|
|
@@ -107,7 +108,7 @@ namespace Avalonia.Controls.Presenters
|
|
|
private int _selectionStart;
|
|
|
private int _selectionEnd;
|
|
|
private bool _caretBlink;
|
|
|
- private string? _text;
|
|
|
+ internal string? _text;
|
|
|
private TextLayout? _textLayout;
|
|
|
private Size _constraint;
|
|
|
|
|
|
@@ -526,23 +527,6 @@ namespace Avalonia.Controls.Presenters
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private string? GetText()
|
|
|
- {
|
|
|
- if (!string.IsNullOrEmpty(_preeditText))
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(_text) || _caretIndex > _text.Length)
|
|
|
- {
|
|
|
- return _preeditText;
|
|
|
- }
|
|
|
-
|
|
|
- var text = _text.Substring(0, _caretIndex) + _preeditText + _text.Substring(_caretIndex);
|
|
|
-
|
|
|
- return text;
|
|
|
- }
|
|
|
-
|
|
|
- return _text;
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Creates the <see cref="TextLayout"/> used to render the text.
|
|
|
/// </summary>
|
|
|
@@ -551,7 +535,7 @@ namespace Avalonia.Controls.Presenters
|
|
|
{
|
|
|
TextLayout result;
|
|
|
|
|
|
- var text = GetText();
|
|
|
+ var text = _text;
|
|
|
|
|
|
var typeface = new Typeface(FontFamily, FontStyle, FontWeight);
|
|
|
|
|
|
@@ -564,7 +548,7 @@ namespace Avalonia.Controls.Presenters
|
|
|
|
|
|
var foreground = Foreground;
|
|
|
|
|
|
- if(_compositionRegion != null)
|
|
|
+ if (_compositionRegion != null)
|
|
|
{
|
|
|
var preeditHighlight = new ValueSpan<TextRunProperties>(_compositionRegion?.Start ?? 0, _compositionRegion?.Length ?? 0,
|
|
|
new GenericTextRunProperties(typeface, FontSize,
|
|
|
@@ -851,7 +835,7 @@ namespace Avalonia.Controls.Presenters
|
|
|
CaretChanged();
|
|
|
}
|
|
|
|
|
|
- private void UpdateCaret(CharacterHit characterHit, bool updateCaretIndex = true)
|
|
|
+ internal void UpdateCaret(CharacterHit characterHit, bool notify = true)
|
|
|
{
|
|
|
_lastCharacterHit = characterHit;
|
|
|
|
|
|
@@ -879,7 +863,7 @@ namespace Avalonia.Controls.Presenters
|
|
|
CaretBoundsChanged?.Invoke(this, EventArgs.Empty);
|
|
|
}
|
|
|
|
|
|
- if (updateCaretIndex)
|
|
|
+ if (notify)
|
|
|
{
|
|
|
SetAndRaise(CaretIndexProperty, ref _caretIndex, caretIndex);
|
|
|
}
|
|
|
@@ -899,35 +883,6 @@ namespace Avalonia.Controls.Presenters
|
|
|
_caretTimer.Tick -= CaretTimerTick;
|
|
|
}
|
|
|
|
|
|
- protected void OnPreeditTextChanged(string? oldValue, string? newValue)
|
|
|
- {
|
|
|
- InvalidateTextLayout();
|
|
|
-
|
|
|
- if (string.IsNullOrEmpty(newValue))
|
|
|
- {
|
|
|
- UpdateCaret(_lastCharacterHit);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var textPosition = _caretIndex + newValue?.Length ?? 0;
|
|
|
-
|
|
|
- var characterHit = GetCharacterHitFromTextPosition(textPosition);
|
|
|
-
|
|
|
- UpdateCaret(characterHit, false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private CharacterHit GetCharacterHitFromTextPosition(int textPosition)
|
|
|
- {
|
|
|
- var lineIndex = TextLayout.GetLineIndexFromCharacterIndex(textPosition, true);
|
|
|
-
|
|
|
- var textLine = TextLayout.TextLines[lineIndex];
|
|
|
-
|
|
|
- var characterHit = textLine.GetNextCaretCharacterHit(new CharacterHit(textPosition - 1));
|
|
|
-
|
|
|
- return characterHit;
|
|
|
- }
|
|
|
-
|
|
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
|
{
|
|
|
base.OnPropertyChanged(change);
|
|
|
@@ -935,11 +890,6 @@ namespace Avalonia.Controls.Presenters
|
|
|
switch (change.Property.Name)
|
|
|
{
|
|
|
case nameof(PreeditText):
|
|
|
- {
|
|
|
- OnPreeditTextChanged(change.OldValue as string, change.NewValue as string);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
case nameof(CompositionRegion):
|
|
|
case nameof(Foreground):
|
|
|
case nameof(FontSize):
|