From b771ce4a4136cfcdf238d12e19859e0c20cb0579 Mon Sep 17 00:00:00 2001 From: Sour Date: Thu, 17 Oct 2024 19:29:13 +0900 Subject: [PATCH] Debugger: Memory Viewer - Improve behavior when pasting multi-line text in search box --- UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs | 6 ++++++ UI/Debugger/Windows/MemoryViewerFindWindow.axaml | 6 ++++++ UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs b/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs index 49f461e68..538136667 100644 --- a/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs +++ b/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs @@ -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; diff --git a/UI/Debugger/Windows/MemoryViewerFindWindow.axaml b/UI/Debugger/Windows/MemoryViewerFindWindow.axaml index 9bcaca27b..684e90fa7 100644 --- a/UI/Debugger/Windows/MemoryViewerFindWindow.axaml +++ b/UI/Debugger/Windows/MemoryViewerFindWindow.axaml @@ -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" /> diff --git a/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs b/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs index 114269d67..c9a3e8087 100644 --- a/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs +++ b/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs @@ -1,5 +1,6 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Mesen.Config; @@ -30,6 +31,8 @@ public MemoryViewerFindWindow(MemoryViewerFindViewModel model, MemoryToolsViewMo Activated += MemorySearchWindow_Activated; + AddHandler(InputElement.KeyDownEvent, OnPreviewKeyDown, RoutingStrategies.Tunnel, true); + InitializeComponent(); #if DEBUG this.AttachDevTools(); @@ -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);