Repository navigation
fix: Suppress character insertion in TextBox when Ctrl or Alt modifiers are held - #22721
Conversation
|
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22721/wasm-skia-net9/index.html |
|
The build 197954 found UI Test snapshots differences: Details
|
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…rs are held Co-authored-by: MartinZikmund <[email protected]>
a6a20a3 to
aa9f15b
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the Skia TextBox key handling to prevent unintended character insertion when shortcut modifier keys (Ctrl/Command/Win and, on non-Apple layouts, Alt) are held, aligning WASM/Skia behavior with desktop platforms. It also adds Skia runtime tests covering the Ctrl+letter and Alt+letter scenarios.
Changes:
- Suppress default character insertion when shortcut modifiers are active, while allowing AltGr (Ctrl+Alt) on non-Apple layouts and preserving Option-character input on Apple layouts.
- Add Skia runtime tests to ensure Ctrl+letter and (non-Apple) Alt+letter do not type into a focused TextBox.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs |
Adds modifier-aware filtering in the default keydown path to avoid inserting characters during shortcut combinations, with AltGr/Apple layout exceptions. |
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.skia.cs |
Adds runtime tests asserting Ctrl+letter and Alt+letter don’t insert text (with Apple marked inconclusive for Alt/Option). |
Comments suppressed due to low confidence (2)
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.skia.cs:4889
- The new shortcut-modifier suppression logic includes special cases for the platform command modifier (VirtualKeyModifiers.Windows on Apple / meta) and for AltGr (Ctrl+Alt) allowing character input, but the added tests only cover Ctrl+letter and (non-Apple) Alt+letter. Please add coverage for at least: (1) Command/Windows+letter does not type, and (2) AltGr (Ctrl+Alt) still types the provided Unicode character on non-Apple layouts, to prevent regressions in these newly introduced branches.
[TestMethod]
[GitHubWorkItem("https://github.com/unoplatform/uno/issues/19327")]
public async Task When_Setting_Short_Text_And_Previous_Selection_Is_OutOfBounds()
{
var useOverlay = FeatureConfiguration.TextBox.UseOverlayOnSkia;
using var _ = Disposable.Create(() => FeatureConfiguration.TextBox.UseOverlayOnSkia = useOverlay);
var SUT = new TextBox
{
Width = 150,
Text = "longer text",
TextWrapping = TextWrapping.Wrap,
AcceptsReturn = true
};
SUT.KeyUp += (_, e) =>
{
SUT.Text = "shorter";
e.Handled = true;
};
await UITestHelper.Load(SUT);
SUT.Focus(FocusState.Keyboard);
await WindowHelper.WaitForIdle();
SUT.Select(SUT.Text.Length, 0);
await WindowHelper.WaitForIdle();
SUT.RaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.Escape, VirtualKeyModifiers.None));
await WindowHelper.WaitForIdle();
SUT.RaiseEvent(UIElement.KeyUpEvent, new KeyRoutedEventArgs(SUT, VirtualKey.Escape, VirtualKeyModifiers.None));
}
[TestMethod]
[PlatformCondition(ConditionMode.Exclude, RuntimeTestPlatforms.SkiaWasm)] // needs paste permission
public async Task When_MaxLine_Paste()
{
if (!ApiExtensibility.IsRegistered<IClipboardExtension>())
{
Assert.Inconclusive("Platform does not support clipboard operations.");
}
using var _ = new TextBoxFeatureConfigDisposable();
var SUT = new TextBox
{
MaxLength = 10,
Text = "0123456789",
SelectionStart = 4,
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.skia.cs:4841
- The GitHubWorkItem links point to #20988, but in the PR metadata #20988 appears to be an existing pull request (docs(wasm): Update troubleshooting...) rather than the bug issue this change targets. Please verify the correct issue number for the TextBox modifier typing bug and update these GitHubWorkItem URLs accordingly so test metadata tracks the right work item.
[TestMethod]
[GitHubWorkItem("https://github.com/unoplatform/uno/issues/19327")]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22721/wasm-skia-net9/index.html |
|
The build 211115 found UI Test snapshots differences: Details
|
|
|
GitHub Issue: closes #20988
PR Type:
🐞 Bugfix
What is the current behavior? 🤔
On Skia WASM, pressing
Ctrl+S,Alt+S, or similar unhandled modifier+letter combinations while a TextBox is focused inserts the letter into the input. This happens because the browser'sevent.keyreports the printable character regardless of modifiers, unlike Win32/X11 which filter control characters at the OS level. Thedefaultcase inOnKeyDownSkia()only checks forUnicodeKeypresence, not whether shortcut modifiers are active.What is the new behavior? 🚀
Modifier+letter combinations no longer insert characters. The
defaultcase now checks for active shortcut modifiers before inserting text:PR Checklist ✅
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information ℹ️
Two runtime tests added:
When_Ctrl_Letter_Should_Not_TypeandWhen_Alt_Letter_Should_Not_Type. The Alt test is markedInconclusiveon Apple platforms where Option+letter is valid character input.Original prompt
Ctrl + letterorAlt + lettercombination should not type #22720💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.