Browse Source
Wrap Clipboard.GetTextAsync in a try-catch to mimic WPF default behavior (#14505)
(in WPF this is configurable via FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure but by default in WPF it won't throw)
pull/14530/head
Bartosz Korczyński
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
19 additions and
2 deletions
-
src/Avalonia.Controls/MaskedTextBox.cs
-
src/Avalonia.Controls/TextBox.cs
|
|
@ -216,7 +216,15 @@ namespace Avalonia.Controls |
|
|
if (clipboard is null) |
|
|
if (clipboard is null) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
var text = await clipboard.GetTextAsync(); |
|
|
string? text = null; |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
text = await clipboard.GetTextAsync(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (TimeoutException) |
|
|
|
|
|
{ |
|
|
|
|
|
// Silently ignore.
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (text == null) |
|
|
if (text == null) |
|
|
return; |
|
|
return; |
|
|
|
|
|
@ -1147,7 +1147,16 @@ namespace Avalonia.Controls |
|
|
var clipboard = TopLevel.GetTopLevel(this)?.Clipboard; |
|
|
var clipboard = TopLevel.GetTopLevel(this)?.Clipboard; |
|
|
|
|
|
|
|
|
if (clipboard != null) |
|
|
if (clipboard != null) |
|
|
text = await clipboard.GetTextAsync(); |
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
text = await clipboard.GetTextAsync(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (TimeoutException) |
|
|
|
|
|
{ |
|
|
|
|
|
// Silently ignore.
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(text)) |
|
|
if (string.IsNullOrEmpty(text)) |
|
|
{ |
|
|
{ |
|
|
|