|
16 | 16 | using Avalonia.Controls.Metadata;
|
17 | 17 | using Avalonia.Media.TextFormatting;
|
18 | 18 | using Avalonia.Automation.Peers;
|
| 19 | +using Avalonia.Media.TextFormatting.Unicode; |
19 | 20 | using Avalonia.Threading;
|
20 | 21 |
|
21 | 22 | namespace Avalonia.Controls
|
@@ -837,7 +838,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
837 | 838 |
|
838 | 839 | _scrollViewer = e.NameScope.Find<ScrollViewer>("PART_ScrollViewer");
|
839 | 840 |
|
840 |
| - if(_scrollViewer != null) |
| 841 | + if (_scrollViewer != null) |
841 | 842 | {
|
842 | 843 | _scrollViewer.ScrollChanged += ScrollViewer_ScrollChanged;
|
843 | 844 | }
|
@@ -886,9 +887,9 @@ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e
|
886 | 887 |
|
887 | 888 | private void PresenterPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
888 | 889 | {
|
889 |
| - if(e.Property == TextPresenter.PreeditTextProperty) |
| 890 | + if (e.Property == TextPresenter.PreeditTextProperty) |
890 | 891 | {
|
891 |
| - if(string.IsNullOrEmpty(e.OldValue as string) && !string.IsNullOrEmpty(e.NewValue as string)) |
| 892 | + if (string.IsNullOrEmpty(e.OldValue as string) && !string.IsNullOrEmpty(e.NewValue as string)) |
892 | 893 | {
|
893 | 894 | PseudoClasses.Set(":empty", false);
|
894 | 895 |
|
@@ -1013,7 +1014,7 @@ private void HandleTextInput(string? input)
|
1013 | 1014 | return;
|
1014 | 1015 | }
|
1015 | 1016 |
|
1016 |
| - input = RemoveInvalidCharacters(input); |
| 1017 | + input = SanitizeInputText(input); |
1017 | 1018 |
|
1018 | 1019 | if (string.IsNullOrEmpty(input))
|
1019 | 1020 | {
|
@@ -1066,11 +1067,30 @@ private void HandleTextInput(string? input)
|
1066 | 1067 | }
|
1067 | 1068 | }
|
1068 | 1069 |
|
1069 |
| - private string? RemoveInvalidCharacters(string? text) |
| 1070 | + private string? SanitizeInputText(string? text) |
1070 | 1071 | {
|
1071 | 1072 | if (text is null)
|
1072 | 1073 | return null;
|
1073 | 1074 |
|
| 1075 | + if (!AcceptsReturn) |
| 1076 | + { |
| 1077 | + var lineBreakStart = 0; |
| 1078 | + var graphemeEnumerator = new GraphemeEnumerator(text.AsSpan()); |
| 1079 | + |
| 1080 | + while (graphemeEnumerator.MoveNext(out var grapheme)) |
| 1081 | + { |
| 1082 | + if (grapheme.FirstCodepoint.IsBreakChar) |
| 1083 | + { |
| 1084 | + break; |
| 1085 | + } |
| 1086 | + |
| 1087 | + lineBreakStart += grapheme.Length; |
| 1088 | + } |
| 1089 | + |
| 1090 | + // All lines except the first one are discarded when TextBox does not accept Return key |
| 1091 | + text = text.Substring(0, lineBreakStart); |
| 1092 | + } |
| 1093 | + |
1074 | 1094 | for (var i = 0; i < invalidCharacters.Length; i++)
|
1075 | 1095 | {
|
1076 | 1096 | text = text.Replace(invalidCharacters[i], string.Empty);
|
@@ -1757,7 +1777,7 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
1757 | 1777 | SetCurrentValue(SelectionEndProperty, caretIndex);
|
1758 | 1778 | }
|
1759 | 1779 |
|
1760 |
| - if(SelectionStart != SelectionEnd) |
| 1780 | + if (SelectionStart != SelectionEnd) |
1761 | 1781 | {
|
1762 | 1782 | _presenter.TextSelectionHandleCanvas?.ShowContextMenu();
|
1763 | 1783 | }
|
@@ -2228,7 +2248,7 @@ void UndoRedoHelper<UndoRedoState>.IUndoRedoHost.OnRedoStackChanged()
|
2228 | 2248 |
|
2229 | 2249 | protected override Size MeasureOverride(Size availableSize)
|
2230 | 2250 | {
|
2231 |
| - if(_scrollViewer != null) |
| 2251 | + if (_scrollViewer != null) |
2232 | 2252 | {
|
2233 | 2253 | var maxHeight = double.PositiveInfinity;
|
2234 | 2254 |
|
|
0 commit comments