mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
Ctrl+E / Ctrl+Shift+F previously activated the pane but left keyboard focus wherever it was — the user still had to click the TextBox before typing. Add a FocusRequested event on SearchPaneModel that the view subscribes to and pushes Focus() on the SearchInput TextBox through Dispatcher.UIThread.Post (a tick lets the freshly- active pane surface in the layout so .Focus() actually takes). Assisted-by: Claude:claude-opus-4-7:Claude Codepull/3755/head
4 changed files with 142 additions and 2 deletions
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System.Threading.Tasks; |
||||
|
||||
using Avalonia.Controls; |
||||
using Avalonia.Headless.NUnit; |
||||
using Avalonia.Threading; |
||||
|
||||
using AwesomeAssertions; |
||||
|
||||
using ILSpy.AppEnv; |
||||
using ILSpy.Docking; |
||||
using ILSpy.Search; |
||||
using ILSpy.ViewModels; |
||||
using ILSpy.Views; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.ILSpy.Tests.Search; |
||||
|
||||
[TestFixture] |
||||
public class SearchInputFocusTests |
||||
{ |
||||
[AvaloniaTest] |
||||
public async Task ShowSearchCommand_Raises_FocusRequested_So_The_View_Pushes_Focus_To_The_Input() |
||||
{ |
||||
// Ctrl+E / Ctrl+Shift+F must leave the SearchInput TextBox focused so the user
|
||||
// can start typing immediately. The VM raises FocusRequested; the SearchPane
|
||||
// code-behind subscribes and calls Focus() on the TextBox.
|
||||
|
||||
var window = AppComposition.Current.GetExport<MainWindow>(); |
||||
window.Show(); |
||||
var vm = (MainWindowViewModel)window.DataContext!; |
||||
await vm.AssemblyTreeModel.WaitForAssembliesAsync(minimumCount: 1); |
||||
|
||||
var search = AppComposition.Current.GetExport<SearchPaneModel>(); |
||||
var dockWorkspace = AppComposition.Current.GetExport<DockWorkspace>(); |
||||
|
||||
var fired = 0; |
||||
search.FocusRequested += () => fired++; |
||||
|
||||
dockWorkspace.ShowSearchCommand.Execute(null); |
||||
|
||||
fired.Should().BeGreaterThan(0, |
||||
"ShowSearchCommand must request focus on the search input, not just activate the pane"); |
||||
} |
||||
|
||||
[AvaloniaTest] |
||||
public async Task SearchInput_Is_Focused_After_ShowSearchCommand_Pumps_Through_The_Dispatcher() |
||||
{ |
||||
var window = AppComposition.Current.GetExport<MainWindow>(); |
||||
window.Show(); |
||||
var vm = (MainWindowViewModel)window.DataContext!; |
||||
await vm.AssemblyTreeModel.WaitForAssembliesAsync(minimumCount: 1); |
||||
|
||||
var pane = await window.WaitForComponent<SearchPane>(); |
||||
var dockWorkspace = AppComposition.Current.GetExport<DockWorkspace>(); |
||||
|
||||
dockWorkspace.ShowSearchCommand.Execute(null); |
||||
|
||||
// Focus shifts via a Dispatcher.UIThread.Post so the view has a frame for the
|
||||
// pane to surface in the layout — pump the dispatcher before asserting.
|
||||
Dispatcher.UIThread.RunJobs(); |
||||
|
||||
var input = pane.FindControl<TextBox>("SearchInput"); |
||||
((object?)input).Should().NotBeNull(); |
||||
input!.IsFocused.Should().BeTrue( |
||||
"the TextBox holds keyboard focus after ShowSearchCommand so the user can start typing without a click"); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue