Skip to content

Commit

Permalink
Debugger: Memory Viewer - Improve behavior when pasting multi-line te…
Browse files Browse the repository at this point in the history
…xt in search box
  • Loading branch information
SourMesen committed Oct 17, 2024
1 parent a7cb985 commit b771ce4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public MemoryViewerFindViewModel(MemoryToolsViewModel memToolsModel)
IsString = DataType == SearchDataType.String;
});

this.WhenAnyValue(x => x.SearchString).Subscribe(x => {
if(SearchString.Contains(Environment.NewLine)) {
SearchString = SearchString.Replace(Environment.NewLine, " ");
}
});

this.WhenAnyValue(x => x.DataType, x => x.IntType, x => x.SearchString).Subscribe(x => {
SearchData? searchData = GetSearchData();
IsValid = searchData != null && searchData.Data.Length > 0;
Expand Down
6 changes: 6 additions & 0 deletions UI/Debugger/Windows/MemoryViewerFindWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
Grid.Column="1"
Name="txtValue"
HorizontalAlignment="Stretch"
AcceptsReturn="True"
VerticalContentAlignment="Center"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
Height="21"
MinHeight="21"
Text="{Binding SearchString}"
MaxLength="300"
/>
Expand Down
11 changes: 11 additions & 0 deletions UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Mesen.Config;
Expand Down Expand Up @@ -30,6 +31,8 @@ public MemoryViewerFindWindow(MemoryViewerFindViewModel model, MemoryToolsViewMo

Activated += MemorySearchWindow_Activated;

AddHandler(InputElement.KeyDownEvent, OnPreviewKeyDown, RoutingStrategies.Tunnel, true);

InitializeComponent();
#if DEBUG
this.AttachDevTools();
Expand All @@ -41,6 +44,14 @@ private void InitializeComponent()
AvaloniaXamlLoader.Load(this);
}

private void OnPreviewKeyDown(object? sender, KeyEventArgs e)
{
if(e.Key == Key.Enter) {
_viewerModel.Find(SearchDirection.Forward);
e.Handled = true;
}
}

protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
Expand Down

0 comments on commit b771ce4

Please sign in to comment.