Repository: microsoft/PowerToys
File: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.TimeDate/FallbackTimeDateItem.cs (C#)

Code before:

    public FallbackTimeDateItem(SettingsManager settings)
         : base(new NoOpCommand(), Resources.Microsoft_plugin_timedate_fallback_display_title)
    {
        Title = string.Empty;
        Subtitle = string.Empty;
        _settingsManager = settings;
    }

    public override void UpdateQuery(string query)
    {
        if (string.IsNullOrWhiteSpace(query))
        {
            Title = string.Empty;
            Subtitle = string.Empty;
            Command = new NoOpCommand();
            return;
        }

        var items = TimeDateCalculator.ExecuteSearch(_settingsManager, query);

        if (items.Count > 0 &&
            items[0].Title != Resources.Microsoft_plugin_timedate_InvalidInput_ErrorMessageTitle &&
            items[0].Title != Resources.Microsoft_plugin_timedate_ErrorResultTitle)
        {
            Title = items[0].Title;
            Subtitle = items[0].Subtitle;
            Icon = items[0].Icon;
        }
        else
        {
            Title = string.Empty;
            Subtitle = string.Empty;
            Command = new NoOpCommand();
        }
    }
}


Review comment (suggestion):
Emmm...
Actually, I don't want to implement as it.

In fact I remember, TimeDateCalculator.ExecuteSearch(_settingsManager, query) will always return item so you will always see it in the top-level page.

I think we need a real map dictionary to match the query, such as
"now": xxx,
"year": xxx,
etc.

I think it's better.

Code after:
{
    private readonly HashSet<string> _validOptions;
    private SettingsManager _settingsManager;

    public FallbackTimeDateItem(SettingsManager settings)
         : base(new NoOpCommand(), Resources.Microsoft_plugin_timedate_fallback_display_title)
    {
        Title = string.Empty;
        Subtitle = string.Empty;
        _settingsManager = settings;
        _validOptions = new(StringComparer.OrdinalIgnoreCase)
        {
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagDate", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagDateNow", CultureInfo.CurrentCulture),

            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagTime", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagTimeNow", CultureInfo.CurrentCulture),

            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagFormat", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagFormatNow", CultureInfo.CurrentCulture),

            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagWeek", CultureInfo.CurrentCulture),
        };
    }

    public override void UpdateQuery(string query)
    {
        if (!_settingsManager.EnableFallbackItems || string.IsNullOrWhiteSpace(query) || !IsValidQuery(query))
        {
            Title = string.Empty;
            Subtitle = string.Empty;
            Command = new NoOpCommand();
            return;
        }

        var availableResults = AvailableResultsList.GetList(false, _settingsManager);
        ListItem result = null;
        var maxScore = 0;

        foreach (var f in availableResults)
        {
            var score = f.Score(query, f.Label, f.AlternativeSearchTag);
            if (score > maxScore)
            {
                maxScore = score;
                result = f.ToListItem();
            }
        }

        if (result != null)
        {