Skip to content

Commit

Permalink
feat: Support for TextBox.Paste and PasswordBox.Paste on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Oct 18, 2023
1 parent aab94da commit 3c3759a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public bool CanPasteClipboardContent
}
#endif
// Skipping already declared event Windows.UI.Xaml.Controls.PasswordBox.PasswordChanged
#if false || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
#if false || __IOS__ || IS_UNIT_TESTS || false || false || false || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public event global::Windows.UI.Xaml.Controls.TextControlPasteEventHandler Paste
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void ClearUndoRedoHistory()
#endif
// Skipping already declared event Windows.UI.Xaml.Controls.TextBox.SelectionChanged
// Skipping already declared event Windows.UI.Xaml.Controls.TextBox.TextChanged
#if false || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
#if false || __IOS__ || IS_UNIT_TESTS || false || false || false || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public event global::Windows.UI.Xaml.Controls.TextControlPasteEventHandler Paste
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public partial class TextBox : Control, IFrameworkTemplatePoolAware
public event TypedEventHandler<TextBox, TextBoxTextChangingEventArgs> TextChanging;
public event TypedEventHandler<TextBox, TextBoxBeforeTextChangingEventArgs> BeforeTextChanging;
public event RoutedEventHandler SelectionChanged;
#if __SKIA__ || __ANDROID__
#if __SKIA__ || __ANDROID__ || __CROSSRUNTIME__
public event TextControlPasteEventHandler Paste;
#endif

Expand Down
16 changes: 16 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Uno.UI.Xaml;
using Windows.UI.Xaml.Input;
using Uno.UI.Helpers;
using Uno.UI.Xaml.Input;

namespace Windows.UI.Xaml.Controls
{
Expand Down Expand Up @@ -71,22 +72,37 @@ private event EventHandler HtmlInput
remove => UnregisterEventHandler("input", value, GenericEventHandlers.RaiseEventHandler);
}

private event RoutedEventHandlerWithHandled HtmlPaste
{
add => RegisterEventHandler("paste", value, GenericEventHandlers.RaiseRoutedEventHandlerWithHandled);
remove => UnregisterEventHandler("paste", value, GenericEventHandlers.RaiseRoutedEventHandlerWithHandled);
}

internal bool IsMultiline { get; }

private protected override void OnLoaded()
{
base.OnLoaded();

HtmlInput += OnInput;
HtmlPaste += OnPaste;

SetTextNative(_textBox.Text);
}

private bool OnPaste(object sender, RoutedEventArgs e)
{
var args = new TextControlPasteEventArgs();
_textBox.RaisePaste(args);
return args.Handled;
}

private protected override void OnUnloaded()
{
base.OnUnloaded();

HtmlInput -= OnInput;
HtmlPaste -= OnPaste;
}

private void OnInput(object sender, EventArgs eventArgs)
Expand Down

0 comments on commit 3c3759a

Please sign in to comment.