Skip to content

fix: Android browser WASM Backspace support - #22316

Closed
MartinZikmund wants to merge 2 commits into
masterfrom
dev/mazi/backspace-wasm-skia
Closed

MartinZikmund wants to merge 2 commits into
masterfrom
dev/mazi/backspace-wasm-skia

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Jan 8, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: closes #22230, closes #21555

PR Type:

What is the current behavior? 🤔

What is the new behavior? 🚀

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

Copilot AI review requested due to automatic review settings January 8, 2026 18:58
@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform area/automation Categorizes an issue or PR as relevant to project automation labels Jan 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes backspace support on Android browser soft keyboards for WebAssembly Skia TextBox implementation. The issue is that Android soft keyboards return keyCode 229 (IME processing) for all keys, making it impossible to detect backspace via keydown events. The fix uses the beforeinput event to detect delete operations via their inputType, and allows the browser to handle deletions natively.

Key Changes:

  • Uses beforeinput event to detect delete operations on Android soft keyboards
  • Adds flag-based mechanism to skip preventDefault() for delete operations
  • Includes fallback check for ev.key on desktop browsers where beforeinput timing differs
  • Adds manual test sample for validation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
BrowserInvisibleTextBoxViewExtension.ts Core fix - adds beforeinput listener to detect delete operations and skip preventDefault to allow native browser handling
TextBox_Backspace_SoftKeyboard.xaml.cs Code-behind for manual test sample with TextChanged handlers and character count display
TextBox_Backspace_SoftKeyboard.xaml Manual test UI with multiple TextBox/PasswordBox scenarios for testing the fix

Comment on lines +56 to +68
<Border Background="#FFF3E0" CornerRadius="8" Padding="15" Margin="0,20,0,0">
<StackPanel Spacing="8">
<TextBlock Text="Test Instructions:" FontWeight="Bold" />
<TextBlock TextWrapping="Wrap" Text="1. Tap each text field to open the soft keyboard" />
<TextBlock TextWrapping="Wrap" Text="2. Use the backspace key to delete characters" />
<TextBlock TextWrapping="Wrap" Text="3. Verify the text updates correctly after each backspace" />
<TextBlock TextWrapping="Wrap" Text="4. Test with different Android keyboards (GBoard, Samsung, SwiftKey)" />
<TextBlock TextWrapping="Wrap" Text="5. Test with autocomplete enabled and disabled" />
</StackPanel>
</Border>

<!-- Character count display -->
<Border Background="#E3F2FD" CornerRadius="8" Padding="15" Margin="0,10,0,0">

Copilot AI Jan 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XAML uses hard-coded colors for the instruction and character count borders (Background="#FFF3E0" and Background="#E3F2FD"). According to the XAML sample guidelines, UI elements should use ThemeResource for backgrounds and foregrounds to ensure proper theme adaptation between light and dark modes. Consider using theme-aware resources instead of explicit color values.

Copilot uses AI. Check for mistakes.

private void MultilineTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var lineCount = MultilineTextBox.Text.Split('\r').Length;

Copilot AI Jan 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line counting logic splits on '\r', but this may not work correctly across all platforms. Line endings can be '\n' (Unix/Linux), '\r\n' (Windows), or '\r' (old Mac). Consider using a more robust approach like Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).Length or using TextBox's built-in line counting capabilities if available.

Copilot uses AI. Check for mistakes.
// Check if beforeinput indicated this is a delete operation.
// If so, let the browser handle it natively (don't preventDefault).
if (BrowserInvisibleTextBoxViewExtension.skipPreventDefaultForDelete) {
BrowserInvisibleTextBoxViewExtension.skipPreventDefaultForDelete = false;

Copilot AI Jan 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag skipPreventDefaultForDelete is reset to false after being checked, but there's a potential race condition or timing issue. If multiple keydown events occur in quick succession before a single beforeinput event, the flag could be cleared prematurely. Consider using a more robust mechanism, such as storing an event timestamp or ID to pair beforeinput events with their corresponding keydown events.

Suggested change
BrowserInvisibleTextBoxViewExtension.skipPreventDefaultForDelete = false;

Copilot uses AI. Check for mistakes.
Comment on lines +135 to +140
// Also check ev.key for desktop browsers where beforeinput may fire after keydown
// or for cases where beforeinput isn't supported.
if (ev.key === 'Backspace' || ev.key === 'Delete') {
ev.stopPropagation();
return;
}

Copilot AI Jan 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic has a potential issue: the code checks for Backspace/Delete keys at lines 137-140 and returns without calling preventDefault(), but this means these keys will NOT be prevented from their default behavior even on desktop browsers where the original preventDefault() approach may have worked correctly. This could change existing behavior for desktop platforms. Consider checking if this is running on Android or if beforeinput is supported before skipping preventDefault(), to avoid affecting other platforms.

Copilot uses AI. Check for mistakes.
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@morning4coffe-dev

Copy link
Copy Markdown
Member

This is a very similar case to: #22299, when testing the generated link on multiple platform it works well now.

@MartinZikmund The test is not visible in SamplesApp tho, I think it should be included in the https://github.com/unoplatform/uno/blob/master/src/SamplesApp/UITests.Shared/UITests.Shared.projitems

@MartinZikmund
MartinZikmund marked this pull request as ready for review January 16, 2026 15:31
@MartinZikmund

Copy link
Copy Markdown
Member Author

@copilot add the test sample to projitems

Copilot AI commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

@MartinZikmund I've opened a new pull request, #22380, to work on those changes. Once the pull request is ready, I'll request review from you.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ MartinZikmund
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund MartinZikmund linked an issue Feb 12, 2026 that may be closed by this pull request
1 of 2 tasks
Copilot AI review requested due to automatic review settings February 12, 2026 12:56
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/backspace-wasm-skia branch from be81dcb to eabe4d1 Compare February 12, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// preventDefault() from the keydown handler, allowing the browser to handle keyboard
/// input natively and propagate text changes through the oninput event.
/// </summary>
[SampleControlInfo("TextBox", "TextBox_Backspace_SoftKeyboard", description: "Tests backspace on Android soft keyboards", ignoreInSnapshotTests: true)]

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new sample uses [SampleControlInfo(...)], but this repo’s samples discovery/generators are based on Uno.UI.Samples.Controls.SampleAttribute ([Sample(...)]). There are no other SampleControlInfo usages/definitions in the repo, so this sample likely won’t be discovered (and may not even compile depending on references). Switch this to [Sample("TextBox", Name = "TextBox_Backspace_SoftKeyboard", IsManualTest = true, IgnoreInSnapshotTests = true, Description = ...)] (or the equivalent pattern used by other manual tests).

Suggested change
[SampleControlInfo("TextBox", "TextBox_Backspace_SoftKeyboard", description: "Tests backspace on Android soft keyboards", ignoreInSnapshotTests: true)]
[Sample("TextBox", Name = "TextBox_Backspace_SoftKeyboard", IsManualTest = true, IgnoreInSnapshotTests = true, Description = "Tests backspace on Android soft keyboards")]

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +14
/// On Android browsers, soft keyboards return keyCode 229 (IME processing) for all keys,
/// making it impossible to detect Backspace via keydown events. The fix removes
/// preventDefault() from the keydown handler, allowing the browser to handle keyboard
/// input natively and propagate text changes through the oninput event.

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML doc comment says the fix “removes preventDefault() from the keydown handler”, but the implementation is conditional (and also uses stopPropagation() for delete keys). Please update this comment to match the actual behavior so the sample doesn’t document an inaccurate root cause/fix.

Suggested change
/// On Android browsers, soft keyboards return keyCode 229 (IME processing) for all keys,
/// making it impossible to detect Backspace via keydown events. The fix removes
/// preventDefault() from the keydown handler, allowing the browser to handle keyboard
/// input natively and propagate text changes through the oninput event.
/// On Android browsers, soft keyboards often return keyCode 229 (IME processing) for all keys,
/// making it difficult to detect Backspace via keydown events. The fix updates the key handling
/// logic so that Backspace is allowed to be processed by the browser (by not calling
/// preventDefault() in that case) and uses stopPropagation() for delete keys when appropriate,
/// allowing native keyboard input to propagate through the oninput event.

Copilot uses AI. Check for mistakes.
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\TextBox_Backspace_SoftKeyboard.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This projitems change adds the new XAML page, but the corresponding code-behind TextBox_Backspace_SoftKeyboard.xaml.cs is not added to the explicit <Compile Include=...> list (this file does not use globbing). That will cause the sample to fail to build because the partial class / InitializeComponent won’t be compiled. Add a matching <Compile Include="...TextBox_Backspace_SoftKeyboard.xaml.cs"> entry like the other TextBox samples.

Suggested change
</Page>
</Page>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\TextBox_Backspace_SoftKeyboard.xaml.cs">
<DependentUpon>TextBox_Backspace_SoftKeyboard.xaml</DependentUpon>
</Compile>

Copilot uses AI. Check for mistakes.
Comment on lines +139 to +145
// Check if beforeinput indicated this is a delete operation.
// If so, let the browser handle it natively (don't preventDefault).
if (BrowserInvisibleTextBoxViewExtension.skipPreventDefaultForDelete) {
BrowserInvisibleTextBoxViewExtension.skipPreventDefaultForDelete = false;
ev.stopPropagation();
return;
}

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipPreventDefaultForDelete is set to true on beforeinput delete operations, but it’s only cleared inside onkeydown. If a browser fires beforeinput without a subsequent keydown (similar to the earlier Enter workaround), the flag will remain set and the next unrelated keydown will incorrectly skip preventDefault(). Consider clearing/resetting this flag in oninput (or at least resetting it at the start/end of the beforeinput handler when the inputType is not a delete).

Copilot uses AI. Check for mistakes.
Comment on lines +147 to +151
// Fallback for desktop browsers where beforeinput may fire after keydown
if (ev.key === 'Backspace' || ev.key === 'Delete') {
ev.stopPropagation();
return;
}

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Backspace/Delete handling the code now calls stopPropagation() and returns. This prevents the key event from bubbling to document listeners (e.g., BrowserKeyboardInputSource), which may change whether KeyDown/KeyUp events are raised in managed code while a TextBox is focused. If the intent is only to avoid preventDefault() (so native editing works), consider whether stopping propagation is necessary, and verify this doesn’t regress key event delivery/shortcuts on non-Android browsers.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to 4
namespace Uno.UI.Runtime.Skia {
export class BrowserInvisibleTextBoxViewExtension {
private static _exports: any;
private static readonly inputElementId = "uno-input";

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description issue reference format: it uses closes #21555, but repo guidelines require fully-qualified issue links in Fixes/Closes/Related footers. Update it to Closes https://github.com/unoplatform/uno/issues/21555 (and keep PR links out of Fixes/Closes/Related lines).

Copilot uses AI. Check for mistakes.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/automation Categorizes an issue or PR as relevant to project automation platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backspace and caret position do not work on Android browser for WASM app [WASM Skia] Backspace key does not work (TextBox, PasswordBox)

7 participants