Skip to content

Commit 7455ff6

Browse files
committed
Fix Search' action doesn't work when triggered from the Command Palette
1 parent abb9011 commit 7455ff6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/Files.App/Data/Contracts/IAddressToolbarViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@ public interface IAddressToolbarViewModel
3131
public event ItemDraggedOverPathItemEventHandler ItemDraggedOverPathItem;
3232

3333
public event EventHandler RefreshWidgetsRequested;
34-
35-
public void SwitchToSearchMode();
3634
}
3735
}

src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,26 @@ public void SwitchToCommandPaletteMode()
602602
OmnibarCurrentSelectedModeName = OmnibarPaletteModeName;
603603
}
604604

605-
public void SwitchToSearchMode()
605+
public async Task SwitchToSearchMode()
606606
{
607+
// If the Omnibar is already focused such as when the user initiates a search via the Command Palette,
608+
// add a short delay to allow the Command Palette to fully close before switching modes.
609+
var omnibar = AddressToolbar?.FindDescendant("Omnibar") as Omnibar;
610+
if (omnibar is not null && omnibar.IsFocused)
611+
await Task.Delay(100);
612+
607613
OmnibarCurrentSelectedModeName = OmnibarSearchModeName;
608614
}
609615

610-
public void SwitchToPathMode()
616+
public async Task SwitchToPathMode()
611617
{
612-
OmnibarCurrentSelectedModeName = OmnibarPathModeName;
613-
618+
// If the Omnibar is already focused such as when the user initiates the Edit Path action via the
619+
// Command Palette, add a short delay to allow the Command Palette to fully close before switching modes.
614620
var omnibar = AddressToolbar?.FindDescendant("Omnibar") as Omnibar;
621+
if (omnibar is not null && omnibar.IsFocused)
622+
await Task.Delay(100);
623+
624+
OmnibarCurrentSelectedModeName = OmnibarPathModeName;
615625
omnibar?.Focus(FocusState.Programmatic);
616626
omnibar.IsFocused = true;
617627
}
@@ -997,8 +1007,7 @@ await Task.Run(() =>
9971007
HotKeys = command.HotKeys,
9981008
SearchText = OmnibarCommandPaletteModeText,
9991009
})
1000-
.Where(item => item.Text != Commands.OpenCommandPalette.Description.ToString()
1001-
&& item.Text != Commands.EditPath.Description.ToString());
1010+
.Where(item => item.Text != Commands.OpenCommandPalette.Description.ToString());
10021011
});
10031012

10041013
newSuggestions.AddRange(suggestionItems);

0 commit comments

Comments
 (0)