-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Keyboard property in WinUI Editor (#1553)
Co-authored-by: Rachel Kang <[email protected]>
- Loading branch information
1 parent
ffab305
commit 961ec34
Showing
5 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Microsoft.UI.Xaml.Input; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public static class KeyboardExtensions | ||
{ | ||
public static InputScope ToInputScope(this Keyboard self) | ||
{ | ||
if (self == null) | ||
throw new ArgumentNullException("self"); | ||
|
||
var result = new InputScope(); | ||
var name = new InputScopeName(); | ||
|
||
if (self == Keyboard.Default) | ||
{ | ||
name.NameValue = InputScopeNameValue.Default; | ||
} | ||
else if (self == Keyboard.Chat) | ||
{ | ||
name.NameValue = InputScopeNameValue.Chat; | ||
} | ||
else if (self == Keyboard.Email) | ||
{ | ||
name.NameValue = InputScopeNameValue.EmailSmtpAddress; | ||
} | ||
else if (self == Keyboard.Numeric) | ||
{ | ||
name.NameValue = InputScopeNameValue.Number; | ||
} | ||
else if (self == Keyboard.Telephone) | ||
{ | ||
name.NameValue = InputScopeNameValue.TelephoneNumber; | ||
} | ||
else if (self == Keyboard.Text) | ||
{ | ||
name.NameValue = InputScopeNameValue.Default; | ||
} | ||
else if (self == Keyboard.Url) | ||
{ | ||
name.NameValue = InputScopeNameValue.Url; | ||
} | ||
else | ||
{ | ||
var custom = (CustomKeyboard)self; | ||
var capitalizedSentenceEnabled = (custom.Flags & KeyboardFlags.CapitalizeSentence) == KeyboardFlags.CapitalizeSentence; | ||
var capitalizedWordsEnabled = (custom.Flags & KeyboardFlags.CapitalizeWord) == KeyboardFlags.CapitalizeWord; | ||
var capitalizedCharacterEnabled = (custom.Flags & KeyboardFlags.CapitalizeCharacter) == KeyboardFlags.CapitalizeCharacter; | ||
|
||
var spellcheckEnabled = (custom.Flags & KeyboardFlags.Spellcheck) == KeyboardFlags.Spellcheck; | ||
var suggestionsEnabled = (custom.Flags & KeyboardFlags.Suggestions) == KeyboardFlags.Suggestions; | ||
|
||
InputScopeNameValue nameValue = InputScopeNameValue.Default; | ||
|
||
if (capitalizedSentenceEnabled) | ||
{ | ||
if (!spellcheckEnabled) | ||
{ | ||
Debug.WriteLine(null, "CapitalizeSentence only works when spell check is enabled"); | ||
} | ||
} | ||
else if (capitalizedWordsEnabled) | ||
{ | ||
if (!spellcheckEnabled) | ||
{ | ||
Debug.WriteLine(null, "CapitalizeWord only works when spell check is enabled"); | ||
} | ||
|
||
nameValue = InputScopeNameValue.NameOrPhoneNumber; | ||
} | ||
|
||
if (capitalizedCharacterEnabled) | ||
{ | ||
Debug.WriteLine(null, "WinUI does not support CapitalizeCharacter"); | ||
} | ||
|
||
name.NameValue = nameValue; | ||
} | ||
|
||
result.Names.Add(name); | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters