diff --git a/src/Compatibility/Core/src/Windows/EntryRenderer.cs b/src/Compatibility/Core/src/Windows/EntryRenderer.cs index d67595e11752..5ee093afc155 100644 --- a/src/Compatibility/Core/src/Windows/EntryRenderer.cs +++ b/src/Compatibility/Core/src/Windows/EntryRenderer.cs @@ -254,6 +254,7 @@ void UpdateClearButtonVisibility() Control.ClearButtonVisible = Element.ClearButtonVisibility == ClearButtonVisibility.WhileEditing; } + [PortHandler("Pending to port IsSpellCheckEnabled")] void UpdateInputScope() { Entry entry = Element; diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/EntryPage.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/EntryPage.xaml index 28f4a7a619b6..027928866233 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/EntryPage.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/EntryPage.xaml @@ -77,6 +77,10 @@ + diff --git a/src/Core/src/Handlers/Entry/EntryHandler.Windows.cs b/src/Core/src/Handlers/Entry/EntryHandler.Windows.cs index 0053d7daf560..9f1abd22411d 100644 --- a/src/Core/src/Handlers/Entry/EntryHandler.Windows.cs +++ b/src/Core/src/Handlers/Entry/EntryHandler.Windows.cs @@ -100,8 +100,10 @@ public static void MapCharacterSpacing(EntryHandler handler, IEntry entry) handler.NativeView?.UpdateCharacterSpacing(entry); } - [MissingMapper] - public static void MapKeyboard(IViewHandler handler, IEntry entry) { } + public static void MapKeyboard(EntryHandler handler, IEntry entry) + { + handler.NativeView?.UpdateKeyboard(entry); + } void OnNativeKeyUp(object? sender, KeyRoutedEventArgs args) { diff --git a/src/Core/src/Platform/Windows/KeyboardExtensions.cs b/src/Core/src/Platform/Windows/KeyboardExtensions.cs index f0a63ae15b83..017ed74a619d 100644 --- a/src/Core/src/Platform/Windows/KeyboardExtensions.cs +++ b/src/Core/src/Platform/Windows/KeyboardExtensions.cs @@ -6,12 +6,11 @@ namespace Microsoft.Maui { public static class KeyboardExtensions { - public static InputScope ToInputScope(this Keyboard self) + public static InputScopeName ToInputScopeName(this Keyboard self) { if (self == null) - throw new ArgumentNullException("self"); + throw new ArgumentNullException(nameof(self)); - var result = new InputScope(); var name = new InputScopeName(); if (self == Keyboard.Default) @@ -79,8 +78,7 @@ public static InputScope ToInputScope(this Keyboard self) name.NameValue = nameValue; } - result.Names.Add(name); - return result; + return name; } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/MauiTextBox.cs b/src/Core/src/Platform/Windows/MauiTextBox.cs index e6503a6459e6..239593845a37 100644 --- a/src/Core/src/Platform/Windows/MauiTextBox.cs +++ b/src/Core/src/Platform/Windows/MauiTextBox.cs @@ -255,21 +255,26 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => static string DetermineTextFromPassword(string realText, int start, string passwordText) { - var lengthDifference = passwordText.Length - realText.Length; + var rt = realText ?? string.Empty; + + var lengthDifference = passwordText.Length - (rt?.Length ?? 0); if (lengthDifference > 0) - realText = realText.Insert(start - lengthDifference, new string(ObfuscationCharacter, lengthDifference)); + rt = rt.Insert(start - lengthDifference, new string(ObfuscationCharacter, lengthDifference)); else if (lengthDifference < 0) - realText = realText.Remove(start, -lengthDifference); + rt = rt.Remove(start, -lengthDifference); var sb = new StringBuilder(passwordText.Length); for (int i = 0; i < passwordText.Length; i++) - sb.Append(passwordText[i] == ObfuscationCharacter ? realText[i] : passwordText[i]); + sb.Append(passwordText[i] == ObfuscationCharacter ? rt[i] : passwordText[i]); return sb.ToString(); } string Obfuscate(string text, bool leaveLastVisible = false) { + if (string.IsNullOrEmpty(text)) + return string.Empty; + if (!leaveLastVisible) return new string(ObfuscationCharacter, text.Length); diff --git a/src/Core/src/Platform/Windows/ReturnTypeExtensions.cs b/src/Core/src/Platform/Windows/ReturnTypeExtensions.cs deleted file mode 100644 index 6b3a523e173a..000000000000 --- a/src/Core/src/Platform/Windows/ReturnTypeExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Microsoft.UI.Xaml.Input; - -namespace Microsoft.Maui -{ - public static class ReturnTypeExtensions - { - public static InputScope ToNative(this ReturnType returnType) - { - var scopeName = new InputScopeName() - { - NameValue = GetKeyboardButtonType(returnType) - }; - - var inputScope = new InputScope - { - Names = { scopeName } - }; - - return inputScope; - } - - internal static InputScopeNameValue GetKeyboardButtonType(this ReturnType returnType) - { - switch (returnType) - { - case ReturnType.Default: - case ReturnType.Done: - case ReturnType.Go: - case ReturnType.Next: - case ReturnType.Send: - return InputScopeNameValue.Default; - case ReturnType.Search: - return InputScopeNameValue.Search; - default: - throw new NotImplementedException($"ReturnType {returnType} not supported"); - } - } - } -} \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/TextBoxExtensions.cs b/src/Core/src/Platform/Windows/TextBoxExtensions.cs index 7bf382846c38..4059ded7c406 100644 --- a/src/Core/src/Platform/Windows/TextBoxExtensions.cs +++ b/src/Core/src/Platform/Windows/TextBoxExtensions.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Microsoft.Maui.Graphics; using Microsoft.UI.Xaml.Media; @@ -46,8 +47,8 @@ public static void UpdateCharacterSpacing(this MauiTextBox textBox, IEntry entry public static void UpdateReturnType(this MauiTextBox textBox, IEntry entry) { - textBox.InputScope = entry.ReturnType.ToNative(); - } + textBox.UpdateInputScope(entry); + } public static void UpdateClearButtonVisibility(this MauiTextBox textBox, IEntry entry) { @@ -112,7 +113,7 @@ public static void UpdateMaxLength(this MauiTextBox textBox, IEntry entry) if (currentControlText.Length > maxLength) textBox.Text = currentControlText.Substring(0, maxLength); } - + public static void UpdateIsPassword(this MauiTextBox textBox, IEntry entry) { textBox.IsPassword = entry.IsPassword; @@ -138,11 +139,17 @@ internal static void UpdateInputScope(this MauiTextBox textBox, ITextInput textI else { textBox.IsTextPredictionEnabled = textInput.IsTextPredictionEnabled; - - // TODO: Update IsSpellCheckEnabled + textBox.IsSpellCheckEnabled = textInput.IsTextPredictionEnabled; } - textBox.InputScope = textInput.Keyboard.ToInputScope(); + var inputScope = new UI.Xaml.Input.InputScope(); + + if (textInput is IEntry entry && entry.ReturnType == ReturnType.Search) + inputScope.Names.Add(new UI.Xaml.Input.InputScopeName(UI.Xaml.Input.InputScopeNameValue.Search)); + + inputScope.Names.Add(textInput.Keyboard.ToInputScopeName()); + + textBox.InputScope = inputScope; } public static void UpdateHorizontalTextAlignment(this MauiTextBox textBox, IEntry entry) @@ -156,6 +163,11 @@ public static void UpdateHorizontalTextAlignment(this MauiTextBox textBox, IEntr public static void UpdateVerticalTextAlignment(this MauiTextBox textBox, IEntry entry) { textBox.VerticalAlignment = entry.VerticalTextAlignment.ToNativeVerticalAlignment(); - } + } + + public static void UpdateKeyboard(this MauiTextBox textBox, IEntry entry) + { + textBox.UpdateInputScope(entry); + } } } \ No newline at end of file