|
|
|
@ -1,6 +1,8 @@ |
|
|
|
using System; |
|
|
|
using System.Diagnostics; |
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Input.TextInput; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Media.TextFormatting; |
|
|
|
using Avalonia.Threading; |
|
|
|
using Avalonia.Utilities; |
|
|
|
@ -75,7 +77,7 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
get => _textEditable; set |
|
|
|
{ |
|
|
|
if(_textEditable != null) |
|
|
|
if (_textEditable != null) |
|
|
|
{ |
|
|
|
_textEditable.TextChanged -= TextEditable_TextChanged; |
|
|
|
_textEditable.SelectionChanged -= TextEditable_SelectionChanged; |
|
|
|
@ -84,7 +86,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
_textEditable = value; |
|
|
|
|
|
|
|
if(_textEditable != null) |
|
|
|
if (_textEditable != null) |
|
|
|
{ |
|
|
|
_textEditable.TextChanged += TextEditable_TextChanged; |
|
|
|
_textEditable.SelectionChanged += TextEditable_SelectionChanged; |
|
|
|
@ -110,7 +112,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
private void TextEditable_SelectionChanged(object? sender, EventArgs e) |
|
|
|
{ |
|
|
|
if(_parent != null && _textEditable != null) |
|
|
|
if (_parent != null && _textEditable != null) |
|
|
|
{ |
|
|
|
_parent.SelectionStart = _textEditable.SelectionStart; |
|
|
|
_parent.SelectionEnd = _textEditable.SelectionEnd; |
|
|
|
@ -157,16 +159,53 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
public event EventHandler? SurroundingTextChanged; |
|
|
|
|
|
|
|
public void SetPreeditText(string? text) |
|
|
|
private string? _presenterText; |
|
|
|
private int _compositionStart; |
|
|
|
|
|
|
|
public void SetPreeditText(string? preeditText) |
|
|
|
{ |
|
|
|
if (_presenter == null || _parent == null) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
_presenter.CaretIndex = _parent.CaretIndex; |
|
|
|
if (_presenterText is null) |
|
|
|
{ |
|
|
|
_presenterText = _parent.Text ?? ""; |
|
|
|
_compositionStart = _parent.CaretIndex; |
|
|
|
} |
|
|
|
|
|
|
|
var text = GetText(preeditText); |
|
|
|
|
|
|
|
Debug.WriteLine(text); |
|
|
|
|
|
|
|
_presenter._text = text; |
|
|
|
|
|
|
|
_presenter.PreeditText = preeditText; |
|
|
|
|
|
|
|
_presenter.UpdateCaret(new CharacterHit(_compositionStart + (preeditText != null ? preeditText.Length : 0)), false); |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(preeditText)) |
|
|
|
{ |
|
|
|
_presenterText = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private string? GetText(string? preeditText) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(preeditText)) |
|
|
|
{ |
|
|
|
return _presenterText; |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(_presenterText)) |
|
|
|
{ |
|
|
|
return preeditText; |
|
|
|
} |
|
|
|
|
|
|
|
var text = _presenterText.Substring(0, _compositionStart) + preeditText + _presenterText.Substring(_compositionStart); |
|
|
|
|
|
|
|
_presenter.PreeditText = text; |
|
|
|
return text; |
|
|
|
} |
|
|
|
|
|
|
|
public void SetComposingRegion(TextRange? region) |
|
|
|
@ -175,6 +214,7 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
_presenter.CompositionRegion = region; |
|
|
|
} |
|
|
|
|
|
|
|
@ -256,9 +296,9 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(e.Property == TextBox.TextProperty) |
|
|
|
if (e.Property == TextBox.TextProperty) |
|
|
|
{ |
|
|
|
if(_textEditable != null) |
|
|
|
if (_textEditable != null) |
|
|
|
{ |
|
|
|
_textEditable.Text = (string?)e.NewValue; |
|
|
|
} |
|
|
|
|