mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use Highlight matches from Everything
To solve inaccurate highlight when facing Chinese Pinyin searches
This commit is contained in:
parent
83883c4b05
commit
cfd705ca68
4 changed files with 67 additions and 8 deletions
|
|
@ -157,7 +157,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
||||||
Type = EverythingApiDllImport.Everything_IsFolderResult(idx) ? ResultType.Folder :
|
Type = EverythingApiDllImport.Everything_IsFolderResult(idx) ? ResultType.Folder :
|
||||||
EverythingApiDllImport.Everything_IsFileResult(idx) ? ResultType.File :
|
EverythingApiDllImport.Everything_IsFileResult(idx) ? ResultType.File :
|
||||||
ResultType.Volume,
|
ResultType.Volume,
|
||||||
Score = (int)EverythingApiDllImport.Everything_GetResultRunCount( (uint)idx)
|
Score = (int)EverythingApiDllImport.Everything_GetResultRunCount( (uint)idx),
|
||||||
|
HighlightData = EverythingHightlightStringToHighlightList(EverythingApiDllImport.Everything_GetResultHighlightedFileName((uint)idx))
|
||||||
};
|
};
|
||||||
|
|
||||||
yield return result;
|
yield return result;
|
||||||
|
|
@ -208,5 +209,55 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
||||||
}
|
}
|
||||||
finally { _semaphore.Release(); }
|
finally { _semaphore.Release(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert the highlighted string from Everything API to a list of highlight indexes for our Result.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="highlightString">Text inside a * quote is highlighted, two consecutive *'s is a single literal *. For example, in the highlighted text: abc*123* the 123 part is highlighted.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static List<int> EverythingHightlightStringToHighlightList(string highlightString)
|
||||||
|
{
|
||||||
|
var highlightData = new List<int>();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(highlightString))
|
||||||
|
return highlightData;
|
||||||
|
|
||||||
|
var isHighlighted = false;
|
||||||
|
var actualIndex = 0; // Index in the actual string (without * markers)
|
||||||
|
var length = highlightString.Length;
|
||||||
|
|
||||||
|
for (var i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
if (highlightString[i] == '*')
|
||||||
|
{
|
||||||
|
// Check if it's a literal * (two consecutive *)
|
||||||
|
if (i + 1 < length && highlightString[i + 1] == '*')
|
||||||
|
{
|
||||||
|
// Two consecutive *'s represent a single literal *
|
||||||
|
if (isHighlighted)
|
||||||
|
{
|
||||||
|
highlightData.Add(actualIndex);
|
||||||
|
}
|
||||||
|
actualIndex++;
|
||||||
|
i++; // Skip the next *
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isHighlighted = !isHighlighted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Regular character
|
||||||
|
if (isHighlighted)
|
||||||
|
{
|
||||||
|
highlightData.Add(actualIndex);
|
||||||
|
}
|
||||||
|
actualIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return highlightData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
||||||
[DllImport(DLL)]
|
[DllImport(DLL)]
|
||||||
public static extern bool Everything_GetResultDateRecentlyChanged(uint nIndex, out long lpFileTime);
|
public static extern bool Everything_GetResultDateRecentlyChanged(uint nIndex, out long lpFileTime);
|
||||||
[DllImport(DLL, CharSet = CharSet.Unicode)]
|
[DllImport(DLL, CharSet = CharSet.Unicode)]
|
||||||
public static extern IntPtr Everything_GetResultHighlightedFileName(uint nIndex);
|
public static extern string Everything_GetResultHighlightedFileName(uint nIndex);
|
||||||
[DllImport(DLL, CharSet = CharSet.Unicode)]
|
[DllImport(DLL, CharSet = CharSet.Unicode)]
|
||||||
public static extern IntPtr Everything_GetResultHighlightedPath(uint nIndex);
|
public static extern IntPtr Everything_GetResultHighlightedPath(uint nIndex);
|
||||||
[DllImport(DLL, CharSet = CharSet.Unicode)]
|
[DllImport(DLL, CharSet = CharSet.Unicode)]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -64,9 +65,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
return result.Type switch
|
return result.Type switch
|
||||||
{
|
{
|
||||||
ResultType.Folder or ResultType.Volume =>
|
ResultType.Folder or ResultType.Volume =>
|
||||||
CreateFolderResult(Path.GetFileName(result.FullPath), result.FullPath, result.FullPath, query, result.Score, result.WindowsIndexed),
|
CreateFolderResult(Path.GetFileName(result.FullPath), result.FullPath, result.FullPath, query, result.Score, result.WindowsIndexed, result.HighlightData),
|
||||||
ResultType.File =>
|
ResultType.File =>
|
||||||
CreateFileResult(result.FullPath, query, result.Score, result.WindowsIndexed),
|
CreateFileResult(result.FullPath, query, result.Score, result.WindowsIndexed, result.HighlightData),
|
||||||
_ => throw new ArgumentOutOfRangeException(null)
|
_ => throw new ArgumentOutOfRangeException(null)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +93,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool windowsIndexed = false)
|
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool windowsIndexed = false, List<int> HighlightData = null)
|
||||||
{
|
{
|
||||||
return new Result
|
return new Result
|
||||||
{
|
{
|
||||||
|
|
@ -100,7 +101,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
IcoPath = path,
|
IcoPath = path,
|
||||||
SubTitle = subtitle,
|
SubTitle = subtitle,
|
||||||
AutoCompleteText = GetAutoCompleteText(title, query, path, ResultType.Folder),
|
AutoCompleteText = GetAutoCompleteText(title, query, path, ResultType.Folder),
|
||||||
TitleHighlightData = Context.API.FuzzySearch(query.Search, title).MatchData,
|
TitleHighlightData = HighlightData ?? Context.API.FuzzySearch(query.Search, title).MatchData,
|
||||||
CopyText = path,
|
CopyText = path,
|
||||||
Preview = new Result.PreviewInfo
|
Preview = new Result.PreviewInfo
|
||||||
{
|
{
|
||||||
|
|
@ -282,7 +283,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool windowsIndexed = false)
|
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool windowsIndexed = false, List<int> HighlightData = null)
|
||||||
{
|
{
|
||||||
var isMedia = IsMedia(Path.GetExtension(filePath));
|
var isMedia = IsMedia(Path.GetExtension(filePath));
|
||||||
var title = Path.GetFileName(filePath) ?? string.Empty;
|
var title = Path.GetFileName(filePath) ?? string.Empty;
|
||||||
|
|
@ -302,7 +303,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
FilePath = filePath,
|
FilePath = filePath,
|
||||||
},
|
},
|
||||||
AutoCompleteText = GetAutoCompleteText(title, query, filePath, ResultType.File),
|
AutoCompleteText = GetAutoCompleteText(title, query, filePath, ResultType.File),
|
||||||
TitleHighlightData = Context.API.FuzzySearch(query.Search, title).MatchData,
|
TitleHighlightData = HighlightData ?? Context.API.FuzzySearch(query.Search, title).MatchData,
|
||||||
Score = score,
|
Score = score,
|
||||||
CopyText = filePath,
|
CopyText = filePath,
|
||||||
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath, ResultType.File)),
|
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath, ResultType.File)),
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,18 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.Explorer.Search
|
namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
{
|
{
|
||||||
public record struct SearchResult
|
public record struct SearchResult
|
||||||
{
|
{
|
||||||
|
public SearchResult()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public string FullPath { get; init; }
|
public string FullPath { get; init; }
|
||||||
public ResultType Type { get; init; }
|
public ResultType Type { get; init; }
|
||||||
public int Score { get; init; }
|
public int Score { get; init; }
|
||||||
|
|
||||||
public bool WindowsIndexed { get; init; }
|
public bool WindowsIndexed { get; init; }
|
||||||
|
public List<int> HighlightData { get; init; } = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue