Improve global search: Add diffing from results with query highlighting

Users can now open a diff for a specific search hit directly from the global search results. The original search query will be highlighted within the diff view, making it easier to locate the relevant changes.

Additionally, add `--no-textconv` to git commands used in search and diff operations. This prevents failures when git encounters binary files that textconv drivers might otherwise attempt to process.
This commit is contained in:
Christoph Brandau
2026-06-30 20:32:59 +02:00
parent 2cc1d34fc3
commit 405f302db9
5 changed files with 94 additions and 20 deletions
+32 -13
View File
@@ -96,8 +96,10 @@
let comparison: GitCommitComparison | null = null;
let compareDialogOpen = false;
let selectedDiffPath = "";
let diffHighlightQuery = "";
let pendingRestoreFile: { commit: GitCommit; file: GitCommitFile } | null = null;
let globalSearchOpen = false;
let lastSearchQuery = "";
let globalSearchResults: GitSearchHit[] = [];
let globalSearchBusy = false;
let globalSearchError = "";
@@ -746,6 +748,7 @@
const result = await compareCommits(activeRepoPath, compareFrom, compareTo);
comparison = result;
selectedDiffPath = result.files[0]?.path ?? "";
diffHighlightQuery = "";
pendingRestoreFile = null;
compareDialogOpen = true;
});
@@ -757,6 +760,19 @@
const result = await diffFileAgainstWorkingTree(activeRepoPath, historyCommit.hash, selectedExplorerPath);
comparison = result;
selectedDiffPath = result.files[0]?.path ?? selectedExplorerPath;
diffHighlightQuery = "";
pendingRestoreFile = null;
compareDialogOpen = true;
});
}
async function diffSearchHit(hit: GitSearchHit) {
if (!activeRepoPath) return;
await runOperation(`Diffing ${hit.file}`, async () => {
const result = await diffFileAgainstWorkingTree(activeRepoPath, hit.commit_hash, hit.file);
comparison = result;
selectedDiffPath = result.files[0]?.path ?? hit.file;
diffHighlightQuery = lastSearchQuery;
pendingRestoreFile = null;
compareDialogOpen = true;
});
@@ -785,6 +801,7 @@
if (!activeRepoPath || globalSearchBusy) return;
const searchId = `search-${Date.now()}-${Math.random().toString(36).slice(2)}`;
globalSearchId = searchId;
lastSearchQuery = query;
globalSearchBusy = true;
globalSearchError = "";
globalSearchResults = [];
@@ -1109,19 +1126,6 @@
/>
{/if}
<!-- Compare diff dialog -->
{#if compareDialogOpen && comparison}
<CompareDialog
{comparison}
{selectedDiffPath}
{isBusy}
restoreLabel={pendingRestoreFile ? "Restore file" : ""}
onClose={closeCompareDialog}
onRestore={restorePreviewedCommitFile}
onSelectFile={selectDiffFile}
/>
{/if}
{#if globalSearchOpen}
<GlobalSearchDialog
{hasRepository}
@@ -1132,6 +1136,21 @@
onClose={closeGlobalSearchDialog}
onSearch={runGlobalSearch}
onCancel={cancelGlobalSearch}
onDiff={diffSearchHit}
/>
{/if}
<!-- Compare diff dialog (rendered last so it overlays the search dialog when opened from a hit) -->
{#if compareDialogOpen && comparison}
<CompareDialog
{comparison}
{selectedDiffPath}
{isBusy}
highlightQuery={diffHighlightQuery}
restoreLabel={pendingRestoreFile ? "Restore file" : ""}
onClose={closeCompareDialog}
onRestore={restorePreviewedCommitFile}
onSelectFile={selectDiffFile}
/>
{/if}