forked from WalletWasabi/WalletWasabi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/master' into speed-up-icons
- Loading branch information
Showing
31 changed files
with
482 additions
and
89 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
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
WalletWasabi.Fluent/Behaviors/WhitespaceInputRemovalBehavior.cs
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,29 @@ | ||
using System.Reactive.Disposables; | ||
using System.Reactive.Linq; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
using WalletWasabi.Extensions; | ||
using WalletWasabi.Fluent.Extensions; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class WhitespaceInputRemovalBehavior : DisposingBehavior<TextBox> | ||
{ | ||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
if (AssociatedObject != null) | ||
{ | ||
AssociatedObject.OnEvent(InputElement.TextInputEvent, RoutingStrategies.Tunnel) | ||
.Select(x => x.EventArgs) | ||
.Do(x => Filter(x, x.Text)) | ||
.Subscribe(); | ||
} | ||
} | ||
|
||
private void Filter(TextInputEventArgs textInputEventArgs, string? objText) | ||
{ | ||
textInputEventArgs.Text = objText?.WithoutWhitespace(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
WalletWasabi.Fluent/Behaviors/WhitespacePasteRemovalBehavior.cs
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,43 @@ | ||
using System.Reactive.Disposables; | ||
using System.Reactive.Linq; | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
using ReactiveUI; | ||
using WalletWasabi.Extensions; | ||
using WalletWasabi.Fluent.Helpers; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class WhitespacePasteRemovalBehavior : DisposingBehavior<TextBox> | ||
{ | ||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
var tb = AssociatedObject; | ||
|
||
if (tb != null) | ||
{ | ||
var pasteEvents = Observable.FromEventPattern<EventHandler<RoutedEventArgs>, RoutedEventArgs>( | ||
eh => tb.PastingFromClipboard += eh, eh => tb.PastingFromClipboard -= eh); | ||
|
||
pasteEvents | ||
.Do(args => args.EventArgs.Handled = true) // Always mark the attempt to paste as handled, so we'll always use the customized paste. | ||
.Select(_ => Observable.FromAsync(ApplicationHelper.GetTextAsync, scheduler: RxApp.MainThreadScheduler)) // Executes get text asynchronously using the UI thread | ||
.Concat() // Concatenates the results of the requests into a single observable | ||
.Do(clipboardText => Paste(clipboardText, tb)) // Pastes the text | ||
.Subscribe() | ||
.DisposeWith(disposables); | ||
} | ||
} | ||
|
||
private static void Paste(string text, TextBox tb) | ||
{ | ||
var pasted = text.WithoutWhitespace(); | ||
var start = Math.Min(tb.SelectionStart, tb.SelectionEnd); | ||
var end = Math.Max(tb.SelectionStart, tb.SelectionEnd); | ||
|
||
var current = tb.Text ?? ""; | ||
tb.Text = current[..start] + pasted + current[end..]; | ||
tb.CaretIndex = start + pasted.Length; | ||
} | ||
} |
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
Oops, something went wrong.