diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index f2050cc9f78..ead977cb165 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; @@ -13,7 +12,6 @@ namespace Flow.Launcher.Plugin /// public class Result { - private string _pluginDirectory; private string _icoPath; @@ -103,7 +101,6 @@ public string IcoPath /// public GlyphInfo Glyph { get; init; } - /// /// An action to take in the form of a function call when the result has been selected. /// @@ -206,6 +203,17 @@ public Result Clone() TitleHighlightData = TitleHighlightData, OriginQuery = OriginQuery, PluginDirectory = PluginDirectory, + ContextData = ContextData, + PluginID = PluginID, + TitleToolTip = TitleToolTip, + SubTitleToolTip = SubTitleToolTip, + PreviewPanel = PreviewPanel, + ProgressBar = ProgressBar, + ProgressBarColor = ProgressBarColor, + Preview = Preview, + AddSelectedCount = AddSelectedCount, + GetTitleKey = GetTitleKey, + GetSubTitleKey = GetSubTitleKey, }; } @@ -273,6 +281,26 @@ public ValueTask ExecuteAsync(ActionContext context) /// public const int MaxScore = int.MaxValue; + /// + /// An action to get the key of the title. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records. + /// This can be useful when your plugin will change the title of the result dynamically. + /// + /// + /// The function is invoked with the title of the result as the only parameter. + /// Its result determines the key of the title. + /// + public Func GetTitleKey { get; set; } = null; + + /// + /// An action to get the key of the subtitle. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records. + /// This can be useful when your plugin will change the subtitle of the result dynamically. + /// + /// + /// The function is invoked with the subtitle of the result as the only parameter. + /// Its result determines the key of the subtitle. + /// + public Func GetSubTitleKey { get; set; } = null; + /// /// Info of the preview section of a /// diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index cbd0b88fc7e..2e275c304c9 100644 --- a/Flow.Launcher/Storage/TopMostRecord.cs +++ b/Flow.Launcher/Storage/TopMostRecord.cs @@ -52,8 +52,14 @@ public class Record public bool Equals(Result r) { - return Title == r.Title - && SubTitle == r.SubTitle + var titleEqual = r.GetTitleKey != null ? + r.GetTitleKey(Title) == r.GetTitleKey(r.Title) : + Title == r.Title; + var subTitleEqual = r.GetSubTitleKey != null ? + r.GetSubTitleKey(SubTitle) == r.GetSubTitleKey(r.SubTitle) : + SubTitle == r.SubTitle; + return titleEqual + && subTitleEqual && PluginID == r.PluginID; } } diff --git a/Flow.Launcher/Storage/UserSelectedRecord.cs b/Flow.Launcher/Storage/UserSelectedRecord.cs index d6405005dba..b9dc443f4b3 100644 --- a/Flow.Launcher/Storage/UserSelectedRecord.cs +++ b/Flow.Launcher/Storage/UserSelectedRecord.cs @@ -15,7 +15,6 @@ public class UserSelectedRecord [JsonInclude, JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Dictionary records { get; private set; } - public UserSelectedRecord() { recordsWithQuery = new Dictionary(); @@ -45,8 +44,8 @@ private static int GenerateStaticHashCode(string s, int start = HASH_INITIAL) private static int GenerateResultHashCode(Result result) { - int hashcode = GenerateStaticHashCode(result.Title); - return GenerateStaticHashCode(result.SubTitle, hashcode); + int hashcode = GenerateStaticHashCode(result.GetTitleKey != null ? result.GetTitleKey(result.Title) : result.Title); + return GenerateStaticHashCode(result.GetSubTitleKey != null ? result.GetSubTitleKey(result.SubTitle) : result.SubTitle, hashcode); } private static int GenerateQueryAndResultHashCode(Query query, Result result) @@ -58,8 +57,8 @@ private static int GenerateQueryAndResultHashCode(Query query, Result result) int hashcode = GenerateStaticHashCode(query.ActionKeyword); hashcode = GenerateStaticHashCode(query.Search, hashcode); - hashcode = GenerateStaticHashCode(result.Title, hashcode); - hashcode = GenerateStaticHashCode(result.SubTitle, hashcode); + hashcode = GenerateStaticHashCode(result.GetTitleKey != null ? result.GetTitleKey(result.Title) : result.Title, hashcode); + hashcode = GenerateStaticHashCode(result.GetSubTitleKey != null ? result.GetSubTitleKey(result.SubTitle) : result.SubTitle, hashcode); return hashcode; }