Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,24 @@
yield break;
}

for (var idx = 0; idx < EverythingApiDllImport.Everything_GetNumResults(); ++idx)

Check warning on line 144 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`idx` is not a recognized word. (unrecognized-spelling)

Check warning on line 144 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`idx` is not a recognized word. (unrecognized-spelling)
{
if (token.IsCancellationRequested)
{
yield break;
}

EverythingApiDllImport.Everything_GetResultFullPathNameW(idx, buffer, BufferSize);

Check warning on line 151 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`idx` is not a recognized word. (unrecognized-spelling)

var result = new SearchResult
{
// todo the types are wrong. Everything expects uint everywhere, but we send int just above/below. how to fix? Is EverythingApiDllImport autogenerated or handmade?
FullPath = buffer.ToString(),
Type = EverythingApiDllImport.Everything_IsFolderResult(idx) ? ResultType.Folder :

Check warning on line 157 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`idx` is not a recognized word. (unrecognized-spelling)
EverythingApiDllImport.Everything_IsFileResult(idx) ? ResultType.File :
ResultType.Volume,
Score = (int)EverythingApiDllImport.Everything_GetResultRunCount( (uint)idx)
Score = Convert.ToInt32(EverythingApiDllImport.Everything_GetResultRunCount((uint)idx)),
HighlightData = EverythingHighlightStringToHighlightList(EverythingApiDllImport.Everything_GetResultHighlightedFileName((uint)idx))
};

yield return result;
Expand Down Expand Up @@ -208,5 +209,55 @@
}
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>A list of zero-based character indices that should be highlighted.</returns>
public static List<int> EverythingHighlightStringToHighlightList(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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static void Load(string directory)
[DllImport(DLL)]
public static extern bool Everything_GetResultDateRecentlyChanged(uint nIndex, out long lpFileTime);
[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)]
public static extern IntPtr Everything_GetResultHighlightedPath(uint nIndex);
[DllImport(DLL, CharSet = CharSet.Unicode)]
Expand Down
13 changes: 7 additions & 6 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -64,9 +65,9 @@
return result.Type switch
{
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 =>
CreateFileResult(result.FullPath, query, result.Score, result.WindowsIndexed),
CreateFileResult(result.FullPath, query, result.Score, result.WindowsIndexed, result.HighlightData),
_ => throw new ArgumentOutOfRangeException(null)
};
}
Expand All @@ -92,15 +93,15 @@
}
}

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
{
Title = title,
IcoPath = path,
SubTitle = subtitle,
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,
Preview = new Result.PreviewInfo
{
Expand Down Expand Up @@ -138,7 +139,7 @@
}
catch (Exception ex)
{
Context.API.ShowMsgBox(ex.Message, Localize.plugin_explorer_opendir_error());

Check warning on line 142 in Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`opendir` is not a recognized word. (unrecognized-spelling)
return false;
}
}
Expand All @@ -153,7 +154,7 @@
}
catch (Exception ex)
{
Context.API.ShowMsgBox(ex.Message, Localize.plugin_explorer_opendir_error());

Check warning on line 157 in Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`opendir` is not a recognized word. (unrecognized-spelling)
return false;
}
}
Expand Down Expand Up @@ -188,10 +189,10 @@
var title = string.Empty; // hide title when use progress bar,
var driveLetter = path[..1].ToUpper();
DriveInfo drv = new DriveInfo(driveLetter);
var freespace = ToReadableSize(drv.AvailableFreeSpace, 2);

Check warning on line 192 in Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`drv` is not a recognized word. (unrecognized-spelling)
var totalspace = ToReadableSize(drv.TotalSize, 2);

Check warning on line 193 in Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`drv` is not a recognized word. (unrecognized-spelling)
var subtitle = Localize.plugin_explorer_diskfreespace(freespace, totalspace);

Check warning on line 194 in Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`totalspace` is not a recognized word. (unrecognized-spelling)
double usingSize = (Convert.ToDouble(drv.TotalSize) - Convert.ToDouble(drv.AvailableFreeSpace)) / Convert.ToDouble(drv.TotalSize) * 100;

Check warning on line 195 in Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`drv` is not a recognized word. (unrecognized-spelling)

int? progressValue = Convert.ToInt32(usingSize);

Expand Down Expand Up @@ -282,7 +283,7 @@
};
}

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 title = Path.GetFileName(filePath) ?? string.Empty;
Expand All @@ -302,7 +303,7 @@
FilePath = filePath,
},
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,
CopyText = filePath,
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath, ResultType.File)),
Expand Down
10 changes: 9 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using System.Collections.Generic;

namespace Flow.Launcher.Plugin.Explorer.Search
{
public record struct SearchResult
public readonly record struct SearchResult
{
// Constructor is necesssary for record struct
public SearchResult()
{
}

public string FullPath { get; init; }
public ResultType Type { get; init; }
public int Score { get; init; }

public bool WindowsIndexed { get; init; }
public List<int> HighlightData { get; init; } = [];
}
}
Loading